lukeiamyourfather在http://resources.realflow.com上面共享了他的Multithreaded Mesh Proces脚本,这个脚本是用来实现realflow的多线程输出mesh,虽然realflow的nogui模式有"-threads"这个参数,但你会发现即使你指定了"n"个线程,也是没什么不同的,不管是版4还是版本5,lukeiamyourfather的这个脚本很好的解决了这个问题,他把真正的多线程引入到了realflow的mesh输出。
但是他这个脚本是基于python 3.x来写的,你必须使用python 3.x,不然会出错,因为他用到的一些模块在3.x版本里改名了,如果需要用2.6来运行必须将名称改回来。
参考他的脚本,我使用multiprocessing模块也写了一个,multiprocessing在2.6时被归入了标准库,这样3.x版本应该也能用(我没装,所以没试过),不同的是我这个脚本开始的输出信息可能会有点乱,而他的不会(他加了很多锁,我一个也没),其它的基本一致,我试过对比两个脚本的速度,很接近。
"""
#####################################
## ##
## multiprocessingMesh v0.1 ##
## Author: Mack Stone ##
## Date: 2011/01/22 ##
## Email: schistone@gmail.com ##
## blog: http://schi.iteye.com ##
## ##
#####################################
"""
import multiprocessing
import time
import subprocess
import sys, os
# realflow install path
# realflow安装路径,你可能要改它
realflowRootPath = r'C:\Program Files\Next Limit\RealFlow 5'
# print time info
# 输出时间信息
timeInfo = lambda *args: str(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(time.time())))
# Dump subprocess output to /dev/null to keep the terminal window output clean
# 为了让命令行窗口显得干净点
outPut = open('NUL')
# multiprocess class
# 我要输出我想要的信息,所以重写Process
class MeshProcess(multiprocessing.Process):
def __init__(self, func, args, name=''):
super(MeshProcess, self).__init__()
self.name = name
self.func = func
self.args = args
def run(self):
print '>%s -->' % timeInfo(), 'Starting', self.name
self.res = self.func(*self.args)
print '>>%s -->' % timeInfo(), self.name, 'exited'
# start realflow to process mesh
# 使用realflow进行mesh
def processMesh(q, scene, thread):
while not q.empty():
startFrame, endFrame = q.get()
print '>%s -->' % timeInfo(), 'Thread %d starting meshing frame %d - %d' % (thread, startFrame, endFrame)
subprocess.Popen('realflow.exe -nogui -threads 1 -mesh -range %s %s "%s"' % (startFrame, endFrame, scene),
stdout=outPut, stderr=outPut, shell=True, cwd=realflowRootPath).wait()
print '>%s -->' % timeInfo(), 'Thread %d finished meshing frame %d - %d' % (thread, startFrame, endFrame)
def main(args):
helpText = r"""#####################################
## ##
## multiprocessingMesh v0.1 ##
## Author: Mack Stone ##
## Date: 2011/01/22 ##
## Email: schistone@gmail.com ##
## blog: http://schi.iteye.com ##
## ##
#####################################
usage: C:\Python26\python.exe multiprocessingMesh.py startFrame endFrame threadCount sceneFile
Example: C:\Python26\python.exe multiprocessingMesh.py 0 100 8 C:\test\test.flw
"""
# if argv not right print out help
# 输出帮助信息
if len(args) < 4 or not os.path.isfile(args[3]):
print helpText
return 0
startFrame = int(args[0])
endFrame = int(args[1])
threads = int(args[2])
sceneFile = r'%s' % args[3]
# Populate frameList for each threads
# 计算帧列表
frameList = []
incr = (endFrame + 1) / (threads * 2) + 1
startList = [i for i in range(startFrame, endFrame+1, incr)]
endList = [i-1 for i in range(startFrame, endFrame+1, incr)]
endList.append(endFrame)
endList.pop(0)
frameList = zip(startList, endList)
process = []
q = multiprocessing.Queue() # 创建列队
print '>%s -->' % timeInfo(), "Begin meshing process..."
print '>>...'
# create threads
# 创建线程
for i in range(threads):
x = i + 1
p = MeshProcess(processMesh, (q, sceneFile, x),
"Thread %d" % x)
process.append(p)
# start threads
# 线程开始
for i in range(threads):
process[i].start()
# Fill the queue
# 将帧列表放到列队中排队
for f in frameList:
q.put(f)
# end threads
# 线程任务完成,结束线程
for i in range(threads):
process[i].join()
print '>>>...'
print '>>%s -->' % timeInfo(), "End of meshing process"
# exit
# 退出
sys.exit()
if __name__ == '__main__':
main(sys.argv[1:])
使用视频
http://u.115.com/file/f455884023#
multiprocessingMesh.mp4
希望对你们有帮助
分享到:
相关推荐
a spider showing the method of multiprocessing in python
关于运用python实现多任务,这是一个尝试,不一定做的有多好,请大家多提意见
Python_multiprocessing_6_共享内存_shared_memory_(多进程_多核运算_教学教程tutori
多处理Python 2.7 多处理基本代码,在 OSX 上测试。 这只是使用 Python 多处理代码的框架,您需要提供自己的工作函数。
主要介绍了Python多进程库multiprocessing中进程池Pool类的使用详解,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
多线程和多处理python
Python_multiprocessing_4_效率对比_multithreading,_multiprocessing_co
Python_multiprocessing_7_lock_锁__(多进程_多核运算_教学教程tutorial)
Python 使用pyinstaller打包成exe文件后运行出现Failed to execute script ***的解决方案
Python_multiprocessing_3_queue_进程输出_(多进程_多核运算_教学教程tutorial)
Python_multiprocessing_2_创建进程_(多进程_多核运算_教学教程tutorial)
multiprocessing.Pipe([duplex]) 返回2个连接对象(conn1, conn2),代表管道的两端,默认是.../usr/bin/python #coding=utf-8 import os from multiprocessing import Process, Pipe def send(pipe): pipe.send([‘spam
主要介绍了Python3多进程 multiprocessing 模块,结合实例形式详细分析了Python3多进程 multiprocessing 模块的概念、原理、相关方法使用技巧与注意事项,需要的朋友可以参考下
主要介绍了Python进程Multiprocessing模块原理解析,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
主要介绍了Python Multiprocessing多进程 使用tqdm显示进度条的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下
本文实例讲述了Python多进程multiprocessing、进程池用法。分享给大家供大家参考,具体如下: 内容相关: multiprocessing: 进程的创建与运行 进程常用相关函数 进程池: 为什么要有进程池 进程池的创建与运行...
Python multiprocessing.pool创建非守护进程的方法
multiprocessing包是Python中的多进程管理包。它与 threading.Thread类似,可以利用multiprocessing.Process对象来创建一个进程。该进程可以允许放在Python程序内部编写的函数中。该Process对象与Thread对象的用法...
Python_multiprocessing_5_进程池_pool_(多进程_多核运算_教学教程tutorial)