Problem with subprocess.Popen and EINTR

Piet van Oostrum piet-l at vanoostrum.org
Sat Oct 28 17:56:02 EDT 2017


I am using Python 2.7.14 on MacOS Sierra.

I have a small Python program that calls a shell script in a loop with a time.sleep() in it.
The shell script is called with subprocess.Popen(), followed by a subprocess.wait().
No information is exchanged with the shell script.

Once in a while I send a SIGINT to the program to cancel the sleep. I don't know if the sleep is active at the time of the SIGINT, but most of the time it will be as it takes much more time than the shell script.

I do this by having a handler for the SIGINT which does nothing. It is just there to have the SIGINT silently cancel the sleep.

Now after weeks of running correctly it crashed. It appears that the SIGINT came during the Popen. This causes a system call in the Popen to be terminated with EINTR and Popen then retries that system call, but unfortunately it fails. It seems to me that this could be a bug.

Here is the traceback:

Traceback (most recent call last):
  File "/Users/piet/bin/smoveinloop.py", line 86, in <module>
    main()
  File "/Users/piet/bin/smoveinloop.py", line 65, in main
    task = subprocess.Popen([TASK], executable=TASK)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 390, in __init__
    errread, errwrite)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 1001, in _execute_child
    data = _eintr_retry_call(os.read, errpipe_read, 1048576)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/subprocess.py", line 121, in _eintr_retry_call
    return func(*args)
OSError: [Errno 22] Invalid argument

TASK is a string with the name of the shell script.

Can anybody shed some light on this?
-- 
Piet van Oostrum <piet-l at vanoostrum.org>
WWW: http://piet.vanoostrum.org/
PGP key: [8DAE142BE17999C4]




More information about the Python-list mailing list