鱼C论坛

 找回密码
 立即注册
查看: 1435|回复: 2

idle和CMD的输出有什么关系

[复制链接]
发表于 2018-6-26 11:41:20 | 显示全部楼层 |阅读模式
10鱼币
from multiprocessing import Pool
import os, time, random

def long_time_task(name):
        print("Run task %s (%s)..." % (name, os.getpid()))
        start = time.time()
        time.sleep(random.random() * 3)
        end = time.time()
        print("Task %s runs %0.2f seconds." % (name, (end - start)))

if __name__ == '__main__':
        print("Parent process %s." % os.getpid())
        p = Pool(4)
        for i in range(6):
                p.apply_async(long_time_task, args = (i,))
        print("Waiting for all done...")
        p.close()
        print("Closing Pool...")
        p.join()
        print("Done.")

这是测试文件,执行后idle的输出这这样的:
============ RESTART: D:/Documents/python入门/python_codes/Pool.py ============
Parent process 18336.
Waiting for all done...
Closing Pool...
Done.
>>> 
并没有输出print的内容。而在cmd下执行是这样的:
捕获.PNG
这是为什么呢?
在idle下执行Pool.py的话实际上父进程就是python.exe idle这样的吗,于是父进程的标准输入输出重定向在了都在idle中这样的?但是产生的新进程并没有和idle进行相同的处理,所以新进程的输出还是到了cmd那里?
idle本身是一个python代码,不知道我的猜想正不正确。。

想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-6-27 09:24:33 | 显示全部楼层
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-6-28 10:01:29 | 显示全部楼层
是的,idle是用python的tkinter写出来的
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-7-4 17:27

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表