diff options
author | Antoine Pitrou <pitrou@free.fr> | 2017-06-24 17:22:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-06-24 17:22:23 (GMT) |
commit | 13e96cc596d158b98996db3fa291086ea4afecd9 (patch) | |
tree | e5d5abb7f5364b484ca4396ff99986ccac16ed0c /Lib/multiprocessing/popen_fork.py | |
parent | 0ee32c148119031e19c79359f5c4789ee69fa355 (diff) | |
download | cpython-13e96cc596d158b98996db3fa291086ea4afecd9.zip cpython-13e96cc596d158b98996db3fa291086ea4afecd9.tar.gz cpython-13e96cc596d158b98996db3fa291086ea4afecd9.tar.bz2 |
Fix bpo-30596: Add close() method to multiprocessing.Process (#2010)
* Fix bpo-30596: Add close() method to multiprocessing.Process
* Raise ValueError if close() is called before the Process is finished running
* Add docs
* Add NEWS blurb
Diffstat (limited to 'Lib/multiprocessing/popen_fork.py')
-rw-r--r-- | Lib/multiprocessing/popen_fork.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/Lib/multiprocessing/popen_fork.py b/Lib/multiprocessing/popen_fork.py index ca28bf3..5af9d91 100644 --- a/Lib/multiprocessing/popen_fork.py +++ b/Lib/multiprocessing/popen_fork.py @@ -17,6 +17,7 @@ class Popen(object): sys.stdout.flush() sys.stderr.flush() self.returncode = None + self.finalizer = None self._launch(process_obj) def duplicate_for_child(self, fd): @@ -70,5 +71,9 @@ class Popen(object): os._exit(code) else: os.close(child_w) - util.Finalize(self, os.close, (parent_r,)) + self.finalizer = util.Finalize(self, os.close, (parent_r,)) self.sentinel = parent_r + + def close(self): + if self.finalizer is not None: + self.finalizer() |