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

wait_procs won't wait for timeout #470

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

wait_procs won't wait for timeout #470

giampaolo opened this issue May 23, 2014 · 5 comments

Comments

@giampaolo
Copy link
Owner

From crusade...@gmail.com on January 27, 2014 12:40:10

When waiting for 2 or more processes, as soon as the gone processes are more 
than the alive processes, wait_procs() will return, irregardless of the 
remaining timeout.

Attaching patch to psutil-1.2.1; however the same problem affects the latest 
version in mercurial as of Jan 19 2014 (adapting the patch is trivial).

Attachment: psutil_wait_procs.patch

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

@giampaolo
Copy link
Owner Author

From g.rodola on January 27, 2014 17:02:48

I'm not sure I understand.
Are you saying wait_procs() returns immediately even if there are still 
processess to wait for?

@giampaolo
Copy link
Owner Author

From crusade...@gmail.com on January 27, 2014 17:16:21

Yes exactly. The current algorithm goes:

try:
    max_timeout = 1.0 / (len(alive) - len(gone))
except ZeroDivisionError:
    max_timeout = 1.0
timeout = min((deadline - timer()), max_timeout)

So whenever len(gone) > len(alive), the loop breaks and the whole method exits 
prematurely. Also, the algorithm as it is now fails in its intent of having the 
whole loop take a total of 1 cumulative second.

@giampaolo
Copy link
Owner Author

From g.rodola on January 27, 2014 17:52:25

Ah, I see what you mean. I think your patch is incorrect though in that it 
needs to take ZeroDivionError into account.
AFAIU it should just be:

diff --git a/psutil/__init__.py b/psutil/__init__.py
--- a/psutil/__init__.py
+++ b/psutil/__init__.py
@@ -1272,7 +1272,7 @@
             # processes may disappear in the meantime and their PID
             # reused.
             try:
-                max_timeout = 1.0 / (len(alive) - len(gone))
+                max_timeout = 1.0 / len(alive)
             except ZeroDivisionError:
                 max_timeout = 1.0  # one alive remaining
             if timeout is not None:

@giampaolo
Copy link
Owner Author

From g.rodola on January 28, 2014 05:24:59

Inogre my last comment about ZeroDivisionError.
I committed your patch as-is in revision 07229e0f40bd .
Thanks.

Status: FixedInHG
Labels: Milestone-2.0.0

@giampaolo
Copy link
Owner Author

From g.rodola on March 10, 2014 04:36:50

Closing out as fixed as 2.0.0 version is finally out.

Status: Fixed

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