运行多个进程并协调完成

2024-10-08 20:16:04 发布

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

我对波本的工作方式有点困惑,我希望这是一件愚蠢的事情。我从来没有得到一个完成,民意测验似乎返回一些奇怪的(日志附件)

这是使用提供的实用程序(CSSBACKUP)备份三重模式(表空间)

for i in range(len(schematype)):
    schema_base = schemaname + '_' + schematype[i]  # we need this without the trailing space.
    outputstring = base_folder + '\\' + schemaname + '\\' + schema_base + '_' + timestr + '_cssbackup '
    rc = os.unlink(outputstring)   # wont run if there is a backup already
    logstring = base_folder + '\\' + schemaname + '\\' + schema_base + '_' + timestr + '.log'
    exString = "cssbackup " + phys_string + '-schema '+ schema_base + ' ' + '-file ' + outputstring + '-log '+ logstring
    logging.debug(exString)
    processlist.append(subprocess.Popen(exString)) # start a seperate thread for each one, but we don't want to proceed until processlist[].poll == None (thread is complete)
    procdone[i] = False

现在我已经生成了所有进程,我需要同步它们

while finishit < len(schematype):
    time.sleep(CSTU_CFG.get(hostname).get("logintv"))                                   # need a delay to keep this program from thrashing
    for i in range(len(schematype)):                            # check each of the procs
        if procdone[i] is not True:                                 # if it completed, skip it 
           if processlist[i].poll is not None:                  # if it returns something other than "none" it's still running
                logging.debug('   Running '+ schematype[i] + ' ' + str(processlist[i])+ ' '+ str(time.time() - start_time))
                procdone[i] = False
           else:
                procdone[i] = True                              # None was returned so it's finished
                logging.debug('   Ended '+ schematype[i])           # log it 
                finishit = finishit + 1                         # update the count
                processlist[i].kill                             # kill the process that was running ( Saves memory )

logging.debug('Dump functions complete')        

当我运行这个,我没有得到我所期望的。我期待着一个pid的回报,但我没有看到它。所以我得到的对.poll命令没有用处

因此,即使它产生的外壳消失了,程序也会永远运行

我缺少一些基本的东西

谢谢

11:26:26133根,调试运行本地30.014784812927246 11:26:26133根,调试运行中心30.014784812927246 11:26:26133根,调试运行mngt 30.014784812927246 11:26:56148根,调试运行本地60.02956962585449 11:26:56148根,调试运行中心60.02956962585449 11:26:56148根目录,调试运行mngt 60.02956962585449 11:27:26162根,调试运行本地90.04435467720032 11:27:26162根,调试运行中心90.04435467720032 11:27:26162根,调试运行mngt 90.04435467720032 11:27:56177根,调试运行本地120.05913925170898 11:27:56177根,调试运行中心120.05913925170898 11:27:56177根,调试运行mngt 120.05913925170898 11:28:26192根,调试运行本地150.07392406463623


Tags: thedebugforbaseiftimeisschema
1条回答
网友
1楼 · 发布于 2024-10-08 20:16:04

你应该打电话给投票if processlist[i].poll is not None将始终计算为True,因为processlist[i].poll是函数对象,而不是processlist[i].poll()的结果

编辑: 这看起来是个相当复杂的方法

p = multiprocessing.Pool(n)
p.map_async(subprocess.call, commands)

建议您检查多处理模块

相关问题 更多 >

    热门问题