python脚本空闲运行和双击运行时的不同行为

2024-05-08 00:38:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我发现我的简单python脚本在pythonidle(GUI)执行时工作正常,它的目标是并行运行sub\ u脚本。但当我在窗口中双击它并一个接一个地执行子脚本而不是一次运行它们时,它就出错了。我把代码贴在下面。谁能给我一些建议吗?你知道吗

import time, multiprocessing, os, abc

rootdir=os.getcwd()
NProc = 6

def wrapfunc(args)
    return args[0](*args[1:])


if __name__== '__main__':

    print('abc Starts.')
    ti=time.time()
    pool1=multiprocessing.Pool(processes=NProc)
    Childs1 = [[abc.abc, dirpath, filename]
                for dirpath, dirname, filenames in os.walk(rootdir)
                for filename in filenames
                if filename.endswith('.inp')]
    pool_map1 = pool1.map_async( wrapfunc, Childs1 )
    pool1.close()
    pool_map1.wait()
    print('The abc takes {0} to finish.'.format(time.time()-ti))

编辑1:添加了两个图像。2013年10月27日上午11:33 UTC+8:00

Image1: Start by python IDLE (GUI)<;-弹出所有窗口以并行运行。你知道吗

Image2: Start by double clicking (command line)<;-排队并逐个运行。你知道吗


Tags: 脚本iftimeostiargsguifilename