Polling/awaiting HUP on Popen.stdin

It turns out the answer was as trivially simple as: Use EPOLLERR instead of EPOLLHUP.

I have serious doubts that this the right solution*, but it certainly seems to work:

import select, subprocess, time

E = select.epoll()

p = subprocess.Popen(["sh", "-c", "sleep 3"], stdin=subprocess.PIPE)

#time.sleep(5) #Uncomment this line to convince yourself there is no race-condition here
E.register(p.stdin, select.EPOLLERR)

print("Polling...")
evs = E.poll()
print("Caught events!")

assert (p.stdin.fileno(), select.EPOLLERR) in evs

E.close()

*If this isn’t the right solution, then I would, even now, very much like to discover what the right solution is.


(Here’s the completed version of the script from the original question, if anyone cares.)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top