Skip to content

Instantly share code, notes, and snippets.

@Ivoz
Created February 6, 2012 09:37
Show Gist options
  • Save Ivoz/1751079 to your computer and use it in GitHub Desktop.
Save Ivoz/1751079 to your computer and use it in GitHub Desktop.
import sys
import gevent
from gevent import socket, event
if __name__ == "__main__":
s = socket.fromfd(sys.stdin.fileno(), socket.AF_UNIX,
socket.SOCK_STREAM)
print type(s)
e = event.Event()
def rea(sock, ee):
buff = ''
print type(sock)
while True:
buff += sock.recv(128)
while '\n' in buff:
line, buff = buff.split('\n', 1)
ee.set(line)
g = gevent.spawn(rea, s, e)
def pri(ee):
while True:
ee.wait()
print 'stdin::', ee.get()
ee.clear()
g2 = gevent.spawn(pri, e)
gevent.joinall([g, g2])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment