-
-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
BLD: Avoid using os.spawnve in favor of os.spawnv in exec_command #7614
Conversation
The env modifying spawn* function are not thread safe on windows (python issue6476) so avoid using them unless so requested by the caller. References numpy#7607
This isn't my area. @njsmith @juliantaylor Thoughts? |
My concern is that this only makes _exec_command safe in some cases (no env), while adding more spaghetti to the code. Switching to subprocess or even to the thread-safe spawnve posted in the linked issue would simplify the code while making it actually threadsafe in all cases. |
Note that subprocess is not completely thread safe either, it just has different failure modes The situation is greatly improved in Python >= 3.2 and there does exist a backported subprocess32. I did start to work on replacing the exec_command, with subprocess, but considering that that would (probably) cause different bugs, I opted to make this simpler change (that can also be backported) first. |
I just audited the numpy codebase and there appear to be no uses of the |
@njsmith I'm not opposed in principle. The function itself dates to 2003, but it is exposed. I don't see any uses of it in scipy. The documentation says
So adding the ability to modify the evironment was intended, but that doesn't mean it was a good idea ;) Note that the A backward compatible option would be to define a new function to used in its place and deprecate the current function. |
I think subprocess.run introduced in Python 3.5 would be a candidate (interface-wise) to replace exec_command. It is a simple use of Popen's interface and matches the existing exec_command use pattern. It can be 'backported' to support older Python versions (like this) |
Meh, this is a mess, in code that's already a mess, and whose long term trajectory is probably to be removed rather than fixed, so I think I'm changing my vote to just merging and moving on :-). Anyone object? |
@njsmith No, be my guest. |
Let's do this |
Thanks @ales-erjavec |
See numpy/numpy#7614 for context, and numpy/numpy#7862 for the patch submitted upstream. This should fix random failures on our Windows CI builders.
exec_command() is currently a mess of several implementations using outdated Python APIs and various hacks. This rewrites it to use the standard subprocess module. See PR numpy#7614 for previous discussion.
exec_command() is currently a mess of several implementations using outdated Python APIs and various hacks. This rewrites it to use the standard subprocess module. See PR numpy#7614 for previous discussion.
The env modifying spawn* function are not thread safe on windows (python issue6476) so avoid using them unless so requested by the caller.
This is a minimally intrusive fix for the segfaults reported in #7607