Skip to content
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-19675: Terminate processes if construction of a pool is failing. #5614

Merged
merged 5 commits into from
Nov 4, 2018

Conversation

JulienPalard
Copy link
Member

@JulienPalard JulienPalard commented Feb 10, 2018

Trying another implementation of #57, avoiding to terminate all processes of a pool if a single one is failing to fork during the normal execution of the pool.

https://bugs.python.org/issue19675

self._repopulate_pool()
try:
self._repopulate_pool()
except OSError:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Simply except Exception sounds ok to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds OK, it does not make sense to avoid leaking process only on known exceptions, and we're not hiding it.

if p.exitcode is None:
p.terminate()
for p in self._pool:
if p.is_alive():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you need the process to be alive to join it.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Look ok not to test it first.

Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @JulienPalard. See the comments I posted.

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

@JulienPalard
Copy link
Member Author

I have made the requested changes; please review again.

@bedevere-bot
Copy link

Thanks for making the requested changes!

@pitrou: please review the changes made to this pull request.

@pitrou
Copy link
Member

pitrou commented Apr 2, 2018

Thank you @JulienPalard. Do you think you could easily add a test?

@JulienPalard
Copy link
Member Author

@pitrou I'm testing it by changing rlimit, by throwing random "low" value at it until "some" forks succeed and some are failing. It's really bad for a test case, I can try to produce a stable test case, maybe not with rlimit though (will probably be random when running parallel tests?).

@JulienPalard
Copy link
Member Author

@pitrou Tried to write a unit test. It works but I'm not fond of playing with context this way. Does it look OK for someone?

def is_alive(self):
return self.state == 'started'

try:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not assertRaises?

@pitrou
Copy link
Member

pitrou commented Apr 13, 2018

It works but I'm not fond of playing with context this way. Does it look OK for someone?

The MagicMock thing looks fragile to me. Perhaps you can use a real context and temporarily swap out its Process attribute?

@taleinat
Copy link
Contributor

Wouldn't this need to be backported to 2.7 as well?

@matrixise
Copy link
Member

@JulienPalard maybe you could update it with the last master and submit it again.

# Conflicts:
#	Lib/multiprocessing/pool.py
@taleinat
Copy link
Contributor

taleinat commented Nov 4, 2018

@matrixise, merged again.

@matrixise
Copy link
Member

Thanks @taleinat

@JulienPalard
Copy link
Member Author

Oh thanks for bringing it back, forgot it þ

@JulienPalard JulienPalard merged commit 5d236ca into python:master Nov 4, 2018
@miss-islington
Copy link
Contributor

Thanks @JulienPalard for the PR 🌮🎉.. I'm working now to backport this PR to: 3.6, 3.7.
🐍🍒⛏🤖

@miss-islington
Copy link
Contributor

Sorry, @JulienPalard, I could not cleanly backport this to 3.7 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 5d236cafd7126e640fb25541fcc7e0a494450143 3.7

@miss-islington
Copy link
Contributor

Sorry, @JulienPalard, I could not cleanly backport this to 3.6 due to a conflict.
Please backport using cherry_picker on command line.
cherry_picker 5d236cafd7126e640fb25541fcc7e0a494450143 3.6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants