没看懂,明天再记录一下
今天学习关于线程和正则化,但是完全按照博客上编程,结果却出现了错误,关于错误,我也没看懂,记录一下吧。、
from multiprocessing import Process
import os
def run_proc(name):
print('Run child priocess %s (%s)....' % (name,os.getpid()))
if __name__=__main__:
print('Parent process %s.' % os.getpid())
p = Process(target=run_proc,args=('test',))
print('Child process will start.')
p.start()
p.join()
print('Child process end.')
调用ipython ,确出现了以下错误。
%run E:\lenovo\duoxiancheng.py
Parent process 5112.
Child process will start.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
E:\lenovo\duoxiancheng.py in <module>()
7 p = Process(target=run_proc,args=('test',))
8 print('Child process will start.')
----> 9 p.start()
10 p.join()
11 print('Child process end.')
Parent process 5112.
Child process will start.
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
E:\lenovo\duoxiancheng.py in <module>()
7 p = Process(target=run_proc,args=('test',))
8 print('Child process will start.')
----> 9 p.start()
10 p.join()
11 print('Child process end.')
C:\Users\lenovo\Anaconda3\lib\multiprocessing\process.py in start(self)
103 'daemonic processes are not allowed to have children'
104 _cleanup()
--> 105 self._popen = self._Popen(self)
106 self._sentinel = self._popen.sentinel
107 _children.add(self)
103 'daemonic processes are not allowed to have children'
104 _cleanup()
--> 105 self._popen = self._Popen(self)
106 self._sentinel = self._popen.sentinel
107 _children.add(self)
C:\Users\lenovo\Anaconda3\lib\multiprocessing\context.py in _Popen(process_obj)
210 @staticmethod
211 def _Popen(process_obj):
--> 212 return _default_context.get_context().Process._Popen(process_obj)
213
214 class DefaultContext(BaseContext):
210 @staticmethod
211 def _Popen(process_obj):
--> 212 return _default_context.get_context().Process._Popen(process_obj)
213
214 class DefaultContext(BaseContext):
C:\Users\lenovo\Anaconda3\lib\multiprocessing\context.py in _Popen(process_obj)
311 def _Popen(process_obj):
312 from .popen_spawn_win32 import Popen
--> 313 return Popen(process_obj)
314
315 class SpawnContext(BaseContext):
311 def _Popen(process_obj):
312 from .popen_spawn_win32 import Popen
--> 313 return Popen(process_obj)
314
315 class SpawnContext(BaseContext):
C:\Users\lenovo\Anaconda3\lib\multiprocessing\popen_spawn_win32.py in __init__(self, process_obj)
32
33 def __init__(self, process_obj):
---> 34 prep_data = spawn.get_preparation_data(process_obj._name)
35
36 # read end of pipe will be "stolen" by the child process
32
33 def __init__(self, process_obj):
---> 34 prep_data = spawn.get_preparation_data(process_obj._name)
35
36 # read end of pipe will be "stolen" by the child process
C:\Users\lenovo\Anaconda3\lib\multiprocessing\spawn.py in get_preparation_data(name)
171 # or through direct execution (or to leave it alone entirely)
172 main_module = sys.modules['__main__']
--> 173 main_mod_name = getattr(main_module.__spec__, "name", None)
174 if main_mod_name is not None:
175 d['init_main_from_name'] = main_mod_name
171 # or through direct execution (or to leave it alone entirely)
172 main_module = sys.modules['__main__']
--> 173 main_mod_name = getattr(main_module.__spec__, "name", None)
174 if main_mod_name is not None:
175 d['init_main_from_name'] = main_mod_name
AttributeError: module '__main__' has no attribute '__spec__'
(main函数没有这样的属性,那么我应该如何修改呢,还没有想法,线记录一下,以后再说)