给出以下代码:
if __name__ == '__main__':
print "name = main"
multiprocessing.Process(target=r.fetchFiles, args=(r.results.pop(),))
class R:
# ...
def fetchFiles(self, blabla):
with open('/tmp/doyou.txt', 'w+') as f:
f.write('do you do something?')
r
是R
的一个实例。测试文件没有写入。为什么呢?
答案 0 :(得分:1)
流程必须为started:
process = multiprocessing.Process(target=r.fetchFiles, args=(r.results.pop(),))
process.start()
process.join()
一个简单的工作示例:
from multiprocessing import Process
class R:
def print_value(self, value):
print(value)
if __name__ == '__main__':
process = Process(target=R().print_value, args=('a',))
process.start()
process.join()