-
Notifications
You must be signed in to change notification settings - Fork 59
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
Hang in subprocess.Popen() #67
Comments
I think I've bump into this one today(with |
This is a weird case. This is how I (somehow) reproduced it: The test code
The setup process
That is, create a new directory, init a virtualenv, install some dependencies and run the test code 10 times. I've observed an 80% chance that the test code will not finish within 5 seconds. The outputA typical output could look like this:
So most of the time, the My notes
The error rate would drop significantly to around 10%. If we replace
I guess this is what you have seen in your case? refI don't think it's related but the software versions are as follows:
I hope I haven't made any silly mistakes(because I'm facing Guido here. :P ). |
No worries. Alas, I followed your recipe closely but got no errors. So the search for a reproducible testcase continues... |
Hello, I'm not a user of pyannotate, just got a similar issue with myown code and got here while googling. Anyway, I've looked through the code to get familiar with it. Looks like that ```subprocess.Popen` which hangs is a standard Python 2.7 implementation. It has a multithreading issue: If you try to start two or more subprocesses from different threads, they may end in a situation when one of the This happens because the I guess it's not difficult to make a test-case to reproduce the issue now. Hope, this helps. |
Thanks @artem-kamyshev, that's very helpful information. I'll see if I can make time to test that! |
I had this issue too and landed here via Google, like @artem-kamyshev. I managed to track down the issue to not setting This pitfall in |
This is convincing, but it is also not good news -- it means we can't fix this in pyannotate itself, we have to fix the calling application to pass |
in the bug linked by @artem-kamyshev they suggest using subprocess32 |
[UPDATE: If you have this problem, the solution is to pass
close_fds=True
toPopen()
]I've got a use case where a process being traced for type collection uses
subprocess.Popen()
to execute some helper program, and thePopen()
call hangs at the linein
Popen._execute_child()
. (This is Python 2.7 on Mac, i.e. POSIX.)That pipe has
FD_CLOEXEC
, so the child is not hitting theexec()
. Presumably this is because it hangs in aQueue.put()
operation in_trace_dispatch()
(e.g. here).I can think of a gross fix that monkey-patches
os.fork
to disable the profiling hook around thefork()
so the child doesn't do this. But perhaps there's a more elegant solution (without usingos.register_at_fork()
, which is Python 3.7+ only)? Or the tracing hook could check the pid?[UPDATE:] I can't repro this in a small test program. But it's real, and the
os.fork
monkey-patch fixes it. Not sure what to do about it yet, the monkey-patch seems risky.The text was updated successfully, but these errors were encountered: