Skip to content

Instantly share code, notes, and snippets.

@Ivoz
Created February 6, 2012 10:08
Show Gist options
  • Save Ivoz/1751214 to your computer and use it in GitHub Desktop.
Save Ivoz/1751214 to your computer and use it in GitHub Desktop.
import sys
import os
import fcntl
import gevent
from gevent import socket, queue
if __name__ == "__main__":
fcntl.fcntl(sys.stdin, fcntl.F_SETFL, os.O_NONBLOCK)
q = queue.Queue()
def rea():
buff = ''
while True:
socket.wait_read(sys.stdin.fileno())
buff += sys.stdin.read()
while '\n' in buff:
line, buff = buff.split('\n', 1)
q.put(line)
def pri():
for line in q:
print 'stdin::', line
g = gevent.spawn(rea)
g2 = gevent.spawn(pri)
gevent.joinall([g, g2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment