test.py и main.py находятся в одной папке, и я выполняю main.py, интерпретатор сообщает о следующей ошибке.
Среда Python: python2.7.15
howчтобы исправить эту проблему?
Google сказал мне, что эта проблема исправлена в python3.4, но я хочу использовать этот стиль в python 2.7, как это сделать test.py
from multiprocessing import Process, Queue
def interaction(q):
print '*'*50
q.put('-'*50)
q = Queue()
p = Process(target=interaction, args=(q,))
p.start()
p.join()
print q.get()
main.py
if __name__ == '__main__':
execfile('test.py')
Ошибка:
Traceback (most recent call last):
File "C:\sync360\code\python\oobe_test\multiprocessing_test\demorund\main.py", line 3, in <module>
execfile('test.py')
File "test.py", line 13, in <module>
main()
File "test.py", line 10, in main
p.start()
File "C:\Python27\lib\multiprocessing\process.py", line 130, in start
self._popen = Popen(self)
File "C:\Python27\lib\multiprocessing\forking.py", line 277, in __init__
dump(process_obj, to_child, HIGHEST_PROTOCOL)
File "C:\Python27\lib\multiprocessing\forking.py", line 199, in dump
ForkingPickler(file, protocol).dump(obj)
File "C:\Python27\lib\pickle.py", line 224, in dump
self.save(obj)
File "C:\Python27\lib\pickle.py", line 331, in save
self.save_reduce(obj=obj, *rv)
File "C:\Python27\lib\pickle.py", line 425, in save_reduce
save(state)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 655, in save_dict
self._batch_setitems(obj.iteritems())
File "C:\Python27\lib\pickle.py", line 687, in _batch_setitems
save(v)
File "C:\Python27\lib\pickle.py", line 286, in save
f(self, obj) # Call unbound method with explicit self
File "C:\Python27\lib\pickle.py", line 754, in save_global
(obj, module, name))
pickle.PicklingError: Can't pickle <function func at 0x02B3C1B0>: it's not found as __main__.func
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "C:\Python27\lib\multiprocessing\forking.py", line 381, in main
self = load(from_parent)
File "C:\Python27\lib\pickle.py", line 1384, in load
return Unpickler(file).load()
File "C:\Python27\lib\pickle.py", line 864, in load
dispatch[key](self)
File "C:\Python27\lib\pickle.py", line 886, in load_eof
raise EOFError
EOFError
[Finished in 0.3s with exit code 1]