运行多处理循环时的进度检查池.apply.asyn

2024-10-01 09:30:39 发布

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

我到处都在挖掘,但现在我被困住了,我需要社区的帮助。我不是程序员,在一个名为Houdini的VFX程序中很少使用python。你知道吗

使用多重处理,我使用另一个名为hython的程序成批运行楔形任务。你知道吗

任务创建n个文件夹,并用x个文件填充这些文件夹,每个文件夹的文件总数相等,例如

/files/file1/file1…file2 /文件/u 2/file1…file2

池决定可以批量运行这些任务的数量。我正在尝试实现一个进度条,它沿着代码的一侧运行,并每隔x个数量检查一次文件,直到total number of files=total number of files required。你知道吗

另一个可能的选择是hython任务已经可以输出alfred进度报告,但是由于所有的东西都在一起运行,所以我在终端上打印了同一帧的多个副本,这并不能告诉我它们来自哪个循环。你知道吗

下面是供您考虑的代码。你知道吗

# Importing all needed modules
import multiprocessing
from multiprocessing.pool import ThreadPool
import time, timeit
import os

#My Variables
hou.hipFile.load("/home/tricecold/pythonTest/HoudiniWedger/HoudiniWedger.hiplc") #scene file
wedger =   hou.parm('/obj/geo1/popnet/source_first_input/seed') #wedged parameter
cache = hou.node('/out/cacheme') #runs this node
total_tasks = 10 #Wedge Amount
max_number_processes = 5 #Batch Size
FileRange =  abs(hou.evalParmTuple('/out/cacheme/f')[0] - hou.evalParmTuple('/out/cacheme/f')[1])
target_dir = os.path.dirname(hou.evalParm('/out/cacheme/sopoutput')) + "/"
totals = FileRange * total_tasks

def cacheHoudini(wedge=total_tasks): #houdini task definiton
wedger.set(wedge)
time.sleep(0.1)
cache.render(verbose=False)

def files(wedge=total_tasks): #figure out remaining files
    count = 0
    while (count < totals):
        num = len([name for name in os.listdir(target_dir)])
        count = count + 1
        print (count)


if __name__ == '__main__':

    pool = multiprocessing.Pool(max_number_processes) #define pool size
    #do i need to run my progress function files here  
    for wedge in range(0,total_tasks):
        #or I add function files here, not really sure
        pool.apply_async(cacheHoudini,args=(wedge,)) #run tasks

    pool.close() # After all threads started we close the pool
    pool.join() # And wait until all threads are done

Tags: 文件import文件夹numbercountfilesallout