This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: multiprocessing is_alive() between children processes
Type: behavior Stage:
Components: Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: matttimms
Priority: normal Keywords:

Created on 2019-12-10 23:22 by matttimms, last changed 2022-04-11 14:59 by admin.

Files
File name Uploaded Description Edit
is_alive_method.py matttimms, 2019-12-10 23:22
Messages (1)
msg358232 - (view) Author: Matt (matttimms) Date: 2019-12-10 23:22
I'm trying to evaluate process' state between two "sibling" processes (processes created by the same parent process); using the .is_alive() and exitcode to evaluate whether a process has been init'd, started, finished successfully or unsuccessfully. 
The reference to one process is passed to the other and I'd like to call .is_alive(). This raises the following assertion error:

Process C-2:
Traceback (most recent call last):
  File "/usr/lib/python3.7/multiprocessing/process.py", line 297, in _bootstrap
    self.run()
  File "/home/timms/.PyCharm2019.2/config/scratches/is_alive_method.py", line 59, in run
    print("brother - ",self.brother.state)
  File "/home/timms/.PyCharm2019.2/config/scratches/is_alive_method.py", line 16, in state
    if self.is_alive():
  File "/usr/lib/python3.7/multiprocessing/process.py", line 151, in is_alive
    assert self._parent_pid == os.getpid(), 'can only test a child process'
AssertionError: can only test a child process

It's obvious that the assertion fails given the family structure of the processes. Overwriting the is_alive() method in my own process class appears to produce my desired output behaviour - with assertion and discarding self removed (see attachment).

Is there something fundamental to how process' operate that I should be weary of? I understand that is_alive also joins itself if possible; is that the sole reason for the assertion? Could a method that mirrors is_alive() without the assertion and discard method work with the desired intention I've described above?
History
Date User Action Args
2022-04-11 14:59:24adminsetgithub: 83202
2019-12-10 23:22:54matttimmscreate