我测试 python 多处理并编写简单的程序:
from multiprocessing import Process
from time import sleep
def f(name):
print 'hello', name
x=1
while True:
x+=1
sleep(1)
print 'subprocess '+str(x)
if x==10:
quit()
if __name__ == '__main__':
p = Process(target=f, args=('bob',))
p.start()
x=1
while True:
x+=1
sleep(0.1)
print 'main process '+str(x)
if x==100:
quit()
它的工作,但我几乎没有错误:
Traceback (most recent call last):
File "ttt.py", line 17, in <module>
p.start()
File "/usr/lib64/python2.6/multiprocessing/process.py", line 104, in start
self._popen = Popen(self)
File "/usr/lib64/python2.6/multiprocessing/forking.py", line 99, in __init__
code = process_obj._bootstrap()
File "/usr/lib64/python2.6/multiprocessing/process.py", line 242, in _bootstrap
sys.stderr.write(e.args[0] + '\n')
TypeError: unsupported operand type(s) for +: 'NoneType' and 'str'