Skip to content
Open
Show file tree
Hide file tree
Changes from 9 commits
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
9 changes: 9 additions & 0 deletions Doc/library/multiprocessing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,15 @@ The :mod:`multiprocessing` package mostly replicates the API of the

.. versionadded:: 3.7

.. method:: closed()

Return whether the process is closed.

Roughly, a process object is considered closed when :meth:`close`
is called on it.

.. versionadded:: 3.14

.. method:: close()

Close the :class:`Process` object, releasing all resources associated
Expand Down
7 changes: 7 additions & 0 deletions Lib/multiprocessing/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ def is_alive(self):
_children.discard(self)
return False

@property
def 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))
def _test_task():
pass
p = self.Process(target=_test_task)
self.assertFalse(p.closed)
p.close()
self.assertTrue(p.closed)

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

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 ``closed()`` in the :class:`multiprocessing.Process` to
determine whether the process is closed.
Loading