Created
February 6, 2012 10:08
-
-
Save Ivoz/1751214 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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