Skip to content

Commit

Permalink
More accurate @running for Process
Browse files Browse the repository at this point in the history
  • Loading branch information
danijar committed Sep 11, 2024
1 parent c359b54 commit 44bf3f9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion portal/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__version__ = '3.1.12'
__version__ = '3.2.0'

import multiprocessing as mp
try:
Expand Down
9 changes: 8 additions & 1 deletion portal/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,14 @@ def pid(self):
def running(self):
if not self.started:
return False
return self.process.is_alive()
if not self.process.is_alive():
return False
try:
if psutil.Process(self.pid).status() == psutil.STATUS_ZOMBIE:
return False
except psutil.NoSuchProcess:
return False
return True

@property
def exitcode(self):
Expand Down
6 changes: 3 additions & 3 deletions tests/test_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def fn():
worker = portal.Process(fn, start=True)
worker.kill()
assert not worker.running
assert worker.exitcode == -15
assert worker.exitcode < 0

@pytest.mark.parametrize('repeat', range(5))
def test_kill_with_subproc(self, repeat):
Expand All @@ -62,7 +62,7 @@ def inner(ready):
ready.acquire()
worker.kill()
assert not worker.running
assert worker.exitcode == -15
assert worker.exitcode < 0

@pytest.mark.parametrize('repeat', range(5))
def test_kill_with_subthread(self, repeat):
Expand All @@ -79,7 +79,7 @@ def inner(ready):
ready.wait()
worker.kill()
assert not worker.running
assert worker.exitcode == -15
assert worker.exitcode < 0

def test_initfn(self):
def init():
Expand Down
2 changes: 1 addition & 1 deletion tests/test_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,4 @@ def inner(ready):
assert not worker.running
assert not proc[0].running
assert worker.exitcode == 2
assert proc[0].exitcode == -15
assert proc[0].exitcode < 0

0 comments on commit 44bf3f9

Please sign in to comment.