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

Make Process.wait() busy loop on UNIX a little clever #245

Closed
giampaolo opened this issue May 23, 2014 · 7 comments
Closed

Make Process.wait() busy loop on UNIX a little clever #245

giampaolo opened this issue May 23, 2014 · 7 comments

Comments

@giampaolo
Copy link
Owner

From g.rodola on January 19, 2012 21:35:03

Process.wait(timeout=N) on UNIX is implemented as a busy loop which keeps 
calling os.waitpid() until the process is gone or the timeout is reached.
A time.sleep() call is used to avoid hogging CPU resources: 
https://code.google.com/p/psutil/source/browse/tags/release-0.4.1/psutil/_psposix.py#53
 This is not very smart though, as it keeps sleeping for 0.0001 seconds.
I noticed a better solution used in Lib/subprocess.py which increases the sleep 
interval incrementally, saving a considerable amount of CPU cycles if the 
process dies, say, after 20 seconds: 
http://hg.python.org/cpython/file/053fbceaf789/Lib/subprocess.py#l1407 I think 
it's worth to take that as an example.
Also, we might want to keep an eye on http://bugs.python.org/issue12187 and 
hopefully get rid of the busy loop on some UNIX platforms.

Original issue: http://code.google.com/p/psutil/issues/detail?id=245

@giampaolo giampaolo self-assigned this May 23, 2014
@giampaolo
Copy link
Owner Author

From g.rodola on January 20, 2012 10:53:25

Fixed in r1252 .

Status: FixedInSVN
Labels: Performance

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on January 20, 2012 12:16:23

I didn't get a chance to review this one; did you put in some kind of safeguard 
upper limit? My only concern would be making the sleep delay too large could 
have a negative impact on functionality.

@giampaolo
Copy link
Owner Author

From g.rodola on January 20, 2012 12:19:10

Yep, the limit is 0.04 seconds.

@giampaolo
Copy link
Owner Author

From jlo...@gmail.com on January 20, 2012 12:30:11

Excellent, nice find on this one

@giampaolo
Copy link
Owner Author

From g.rodola on January 30, 2012 04:19:51

Labels: Milestone-0.5.0

@giampaolo
Copy link
Owner Author

From g.rodola on June 27, 2012 11:54:03

0.5.0 is finally out. Closing out as fixed.

Status: Fixed

@giampaolo
Copy link
Owner Author

From g.rodola on March 02, 2013 04:06:41

Updated csets after the SVN -> Mercurial migration: r1252 == revision 
18d53ff30011

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

No branches or pull requests

1 participant