В Python 2 Мне удалось прочитать целевой объект мертвого процесса, но в Python 3 я не могу найти способ сделать то же самое:
Python 2:
# python
Python 2.7.5 (default, Aug 7 2019, 00:51:29)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> def myfunct():
... print("hi")
...
>>> import multiprocessing
>>> p1 = multiprocessing.Process(target=myfunct)
>>> dir(p1)
['_Popen', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_args', '_authkey', '_bootstrap', '_daemonic', '_identity', '_kwargs', '_name', '_parent_pid', '_popen', '_target', '_tempdir', 'authkey', 'daemon', 'exitcode', 'ident', 'is_alive', 'join', 'name', 'pid', 'run', 'start', 'terminate']
>>> p1.start()
>>> hi
>>> dir(p1)
['_Popen', '__class__', '__delattr__', '__dict__', '__doc__', '__format__', '__getattribute__', '__hash__', '__init__', '__module__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_args', '_authkey', '_bootstrap', '_daemonic', '_identity', '_kwargs', '_name', '_parent_pid', '_popen', '_target', '_tempdir', 'authkey', 'daemon', 'exitcode', 'ident', 'is_alive', 'join', 'name', 'pid', 'run', 'start', 'terminate']
>>> p1.is_alive()
False
Атрибут ._target присутствует, даже если процесс не работает
Python 3:
# python3.8
Python 3.8.0 (default, Nov 28 2019, 20:43:25)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> def myfunct():
... print("hi")
...
>>> import multiprocessing
>>> p1 = multiprocessing.Process(target=myfunct)
>>> dir(p1)
['_Popen', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_args', '_bootstrap', '_check_closed', '_closed', '_config', '_identity', '_kwargs', '_name', '_parent_name', '_parent_pid', '_popen', '_start_method', '_target', 'authkey', 'close', 'daemon', 'exitcode', 'ident', 'is_alive', 'join', 'kill', 'name', 'pid', 'run', 'sentinel', 'start', 'terminate']
>>> p1.start()
>>> hi
>>> dir(p1)
['_Popen', '__class__', '__delattr__', '__dict__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__init_subclass__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', '_bootstrap', '_check_closed', '_closed', '_config', '_identity', '_name', '_parent_name', '_parent_pid', '_popen', '_sentinel', '_start_method', 'authkey', 'close', 'daemon', 'exitcode', 'ident', 'is_alive', 'join', 'kill', 'name', 'pid', 'run', 'sentinel', 'start', 'terminate']
>>> p1.is_alive()
False
Здесь, в Python 3, атрибут _target ушел после завершения процесса.
Как его восстановить?