Skip to content

Instantly share code, notes, and snippets.

@saghul
Created May 18, 2016 08:56
Show Gist options
  • Save saghul/97b96f888203ea87f92ae6bd69df3a98 to your computer and use it in GitHub Desktop.
Save saghul/97b96f888203ea87f92ae6bd69df3a98 to your computer and use it in GitHub Desktop.
import errno
import os
import select
def test_fd(fd):
kqueue = select.kqueue()
kevent = select.kevent(fd, filter=select.KQ_FILTER_READ, flags=select.KQ_EV_ADD | select.KQ_EV_ENABLE)
events = kqueue.control([kevent], 1, 0.001)
if not events:
print "fd workss with kqueue"
return
assert len(events) == 1
event = events[0]
if (event.flags & select.KQ_EV_ERROR) == 0 or event.data != errno.EINVAL:
print "fd workss with kqueue"
else:
print "fd does NOT work with kqueue"
tty_fd = os.open('/dev/tty', os.O_RDWR)
print "Testing if kqueue works with /dev/tty"
test_fd(tty_fd)
ttyname = os.ttyname(1)
ttyname_fd = os.open(ttyname, os.O_RDWR)
print "Testing if kqueue works with %s" % ttyname
test_fd(ttyname_fd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment