37,719
社区成员
发帖
与我相关
我的任务
分享
from multiprocessing import Process
import time
def task(msg):
print 'hello, %s' % msg
time.sleep(1)
if __name__ == '__main__':
p = Process(target=task, args=('world',))
p.start()
if p.is_alive():
print 'Process: %s is running' % p.pid
p.join()
python _.py
Traceback (most recent call last):
File "_.py", line 2, in <module>
from multiprocessing import Process
File "D:\Documents\myrep\lang\py\multiprocessing.py", line 4, in <module>
subprocess.call(['dir',],)
File "C:\Python27\lib\subprocess.py", line 168, in call
return Popen(*popenargs, **kwargs).wait()
File "C:\Python27\lib\subprocess.py", line 390, in __init__
errread, errwrite)
File "C:\Python27\lib\subprocess.py", line 640, in _execute_child
startupinfo)
WindowsError: [Error 2]
from multiprocessing import Process, freeze_support
import time
def task(msg):
print 'hello, %s' % msg
time.sleep(1)
if __name__ == '__main__':
freeze_support()
p = Process(target=task, args=('world',))
p.start()
if p.is_alive():
print 'Process: %s is running' % p.pid
p.join()
https://docs.python.org/2/library/multiprocessing.html?highlight=process#windows