Using the following code, poll_obj.poll()
blocks until sleep has completed:
import select, subprocess, time, fcntl, os
poll_obj = select.poll()
popen_obj = subprocess.Popen("sleep 5", stdout=subprocess.PIPE, stderr=subprocess.PIPE,
close_fds=True, shell=True)
fcntl.fcntl(popen_obj.stdout, fcntl.F_SETFL, os.O_NONBLOCK)
fcntl.fcntl(popen_obj.stderr, fcntl.F_SETFL, os.O_NONBLOCK)
poll_obj.register(popen_obj.stdout)
poll_obj.register(popen_obj.stderr)
start_time = time.time()
poll_obj.poll()
print(time.time() - start_time)
It is my understanding that poll_obj.poll()
shouldn't block because the O_NONBLOCK flag is set on the FDs it tracks. It should return None
.
Is there a way to prevent poll_obj.poll()
from blocking?