You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Looking at the code, it looks sufficient to me. The code calls subprocess.wait, which I always thought is enough. And, trying with /usr/bin/python-debug, it appears it is enough. Unless the subprocess redirects outputs, but qdrouterd does not do anything like the following
I am surprised one can get away with the with since the fd clearly escapes out of the with's scope...
The subprocess.Popen#__exit__ in the standard library is implemented like this
def__exit__(self, exc_type, value, traceback):
ifself.stdout:
self.stdout.close()
ifself.stderr:
self.stderr.close()
try: # Flushing a BufferedWriter may raise an errorifself.stdin:
self.stdin.close()
finally:
ifexc_type==KeyboardInterrupt:
# https://bugs.python.org/issue25942# In the case of a KeyboardInterrupt we assume the SIGINT# was also already sent to our child processes. We can't# block indefinitely as that is not user friendly.# If we have not already waited a brief amount of time in# an interrupted .wait() or .communicate() call, do so here# for consistency.ifself._sigint_wait_secs>0:
try:
self._wait(timeout=self._sigint_wait_secs)
exceptTimeoutExpired:
passself._sigint_wait_secs=0# Note that this has been done.return# resume the KeyboardInterrupt# Wait for the process to terminate, to avoid zombies.self.wait()
The text was updated successfully, but these errors were encountered:
File "scratches/scratch_8.py", line 8, in <module>
f.write("aaaa\n")
ValueError: I/O operation on closed file.
The trick is that subprocess forks a new process, so closing file in parent does not influence the fd in child, of course. At least that is my guess. In any case, the following is what router tests do and it works just fine (and does not produce warnings in python-debug -Xdev, which is the most important thing. Useless warnings should not be printed so that we can see any new and interesting ones
import subprocess
with open('file', 'w') as f:
p = subprocess.Popen(["bash", "-c", "sleep 1; echo baf"], stdout=f, stderr=subprocess.STDOUT)
p.wait()
https://github.com/skupperproject/skupper-router/runs/6243241095?check_suite_focus=true#step:9:1043
The stacktrace above is useless, but the test itself is simple and there appears only one place which deals with fd's, the subprocess call.
skupper-router/tests/system_tests_one_router.py
Lines 409 to 415 in 4dac887
Looking at the code, it looks sufficient to me. The code calls
subprocess.wait
, which I always thought is enough. And, trying with/usr/bin/python-debug
, it appears it is enough. Unless the subprocess redirects outputs, but qdrouterd does not do anything like the followingBut
Process
does!skupper-router/tests/system_test.py
Lines 300 to 310 in fdfd076
I am surprised one can get away with the
with
since the fd clearly escapes out of thewith
's scope...The
subprocess.Popen#__exit__
in the standard library is implemented like thisThe text was updated successfully, but these errors were encountered: