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
bpo-30794: added kill() method to multiprocessing.Process #2528
Merged
Merged
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
26b3b52
bpo-30794: added kill() method to multiprocessing.Process
vmsp e8cdbc3
Added entries to documentation and NEWS
vmsp 7f6d00e
Refactored test_terminate and test_kill
vmsp dfd4faf
Fix SIGTERM and SIGKILL being used on Windows for the tests
vmsp 7c25c66
Added "versionadded" marker to the documentation
vmsp 84e0e7a
Fix trailing whitespace in doc
pitrou File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,18 +277,18 @@ def test_process(self): | |
self.assertNotIn(p, self.active_children()) | ||
|
||
@classmethod | ||
def _test_terminate(cls): | ||
def _sleep_some(cls): | ||
time.sleep(100) | ||
|
||
@classmethod | ||
def _test_sleep(cls, delay): | ||
time.sleep(delay) | ||
|
||
def test_terminate(self): | ||
def _kill_process(self, meth): | ||
if self.TYPE == 'threads': | ||
self.skipTest('test not appropriate for {}'.format(self.TYPE)) | ||
|
||
p = self.Process(target=self._test_terminate) | ||
p = self.Process(target=self._sleep_some) | ||
p.daemon = True | ||
p.start() | ||
|
||
|
@@ -309,7 +309,7 @@ def test_terminate(self): | |
# XXX maybe terminating too soon causes the problems on Gentoo... | ||
time.sleep(1) | ||
|
||
p.terminate() | ||
meth(p) | ||
|
||
if hasattr(signal, 'alarm'): | ||
# On the Gentoo buildbot waitpid() often seems to block forever. | ||
|
@@ -333,9 +333,17 @@ def handler(*args): | |
|
||
p.join() | ||
|
||
# sometimes get p.exitcode == 0 on Windows ... | ||
return p.exitcode | ||
|
||
def test_terminate(self): | ||
exitcode = self._kill_process(multiprocessing.Process.terminate) | ||
if os.name != 'nt': | ||
self.assertEqual(exitcode, -signal.SIGTERM) | ||
|
||
def test_kill(self): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like this is duplicating most of |
||
exitcode = self._kill_process(multiprocessing.Process.kill) | ||
if os.name != 'nt': | ||
self.assertEqual(p.exitcode, -signal.SIGTERM) | ||
self.assertEqual(exitcode, -signal.SIGKILL) | ||
|
||
def test_cpu_count(self): | ||
try: | ||
|
@@ -462,7 +470,7 @@ def test_many_processes(self): | |
for p in procs: | ||
self.assertEqual(p.exitcode, 0) | ||
|
||
procs = [self.Process(target=self._test_terminate) | ||
procs = [self.Process(target=self._sleep_some) | ||
for i in range(N)] | ||
for p in procs: | ||
p.start() | ||
|
2 changes: 2 additions & 0 deletions
2
Misc/NEWS.d/next/Library/2017-07-04-22-00-20.bpo-30794.qFwozm.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Added multiprocessing.Process.kill method to terminate using the SIGKILL | ||
signal on Unix. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is a new method, you need a
versionadded
marker a well (see above thesentinel
attribute for an example).