Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

multiprocessing is_alive() between children processes #83202

Open
MattTimms mannequin opened this issue Dec 10, 2019 · 2 comments
Open

multiprocessing is_alive() between children processes #83202

MattTimms mannequin opened this issue Dec 10, 2019 · 2 comments
Labels
3.7 (EOL) end of life topic-multiprocessing type-bug An unexpected behavior, bug, or error

Comments

@MattTimms
Copy link
Mannequin

MattTimms mannequin commented Dec 10, 2019

BPO 39021
Nosy @MattTimms
Files
  • is_alive_method.py
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2019-12-10.23:22:54.787>
    labels = ['type-bug', '3.7']
    title = 'multiprocessing is_alive() between children processes'
    updated_at = <Date 2019-12-10.23:22:54.787>
    user = 'https://github.com/MattTimms'

    bugs.python.org fields:

    activity = <Date 2019-12-10.23:22:54.787>
    actor = 'matttimms'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = []
    creation = <Date 2019-12-10.23:22:54.787>
    creator = 'matttimms'
    dependencies = []
    files = ['48770']
    hgrepos = []
    issue_num = 39021
    keywords = []
    message_count = 1.0
    messages = ['358232']
    nosy_count = 1.0
    nosy_names = ['matttimms']
    pr_nums = []
    priority = 'normal'
    resolution = None
    stage = None
    status = 'open'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue39021'
    versions = ['Python 3.7']

    @MattTimms
    Copy link
    Mannequin Author

    MattTimms mannequin commented Dec 10, 2019

    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?

    @MattTimms MattTimms mannequin added 3.7 (EOL) end of life type-bug An unexpected behavior, bug, or error labels Dec 10, 2019
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @catchthemonster
    Copy link

    Thank you MattTimmis for raising this issue!
    The same thing is happening to me... In my case, I am using a main process to bootstrap mp "fork" processes as daemons. These are long-running processes. Now another also forked daemon receives a dict of process objects but these proc objects references loose for example information: from :
    the same becomes in new forked daemon
    I see no difference in object structure, all process attributes are there and are valid.
    however, I can't use is_alive (like you).I can terminate the process from a secondary process but this creates a defunct process. A possible solution to this problem I think is to join() in the main process after the secondary process actually performs termination(). I am all Unix, so this might be a double fork issue when creating a daemon in Unix world but frankly I am not sure how a daemon is implemented exactly in Python multiprocessing ...
    I am also not clear why forking an object would not pass a proc reference in full and allow actions on it that main process could catch and acknowledge it ...
    Thank you for the workaround on is_alive()

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life topic-multiprocessing type-bug An unexpected behavior, bug, or error
    Projects
    Status: No status
    Development

    No branches or pull requests

    2 participants