Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions Lib/multiprocessing/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ def is_alive(self):
_children.discard(self)
return False

def is_closed(self):
'''
Return whether process is closed
'''
return self._closed

def close(self):
'''
Close the Process object.
Expand Down
15 changes: 15 additions & 0 deletions Lib/test/_test_multiprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,21 @@ def _test_close(cls, rc=0, q=None):
q.get()
sys.exit(rc)

def test_is_close(self):
if self.TYPE == "threads":
self.skipTest('test not appropriate for {}'.format(self.TYPE))
q = self.Queue()
p = self.Process(target=self._test_close, kwargs={'q': q})
self.assertFalse(p.is_closed())
p.close()
self.assertTrue(p.is_closed())

wr = weakref.ref(p)
del p
gc.collect()
self.assertIs(wr(), None)
close_queue(q)

def test_close(self):
if self.TYPE == "threads":
self.skipTest('test not appropriate for {}'.format(self.TYPE))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Add the :meth:`.is_closed()` in the :class:`multiprocessing.Process` to
determine whether the process is closed.
Loading