Skip to content

Instantly share code, notes, and snippets.

@ghoseb
ghoseb / gevent_example.py
Created Jul 27, 2011
Gevent spawn / link example
View gevent_example.py
from gevent import monkey; monkey.patch_all()
import gevent
import gevent.greenlet
from functools import partial
from random import random
import urllib
import urllib2
def on_exception(fun, greenlet):
@denik
denik / ServerRack.py
Created Jun 5, 2011
class for managing multiple servers in gevent
View ServerRack.py
# Class for managing multiple servers or anything with start() and stop() methods
class ServerRack(object):
def __init__(self, servers):
self.servers = servers
def start(self):
started = []
try:
View thrift_gevent.py
import gevent
from thrift.server.TServer import TServer
# XXX Hackish, but should be safe: monkey patch gevent socket support into
# Thrift. Overall I think this is cleaner than reimplementing all of TSocket.
from thrift.transport import TSocket; TSocket.socket = gevent.socket
from thrift.transport.TTransport import TTransportException
class TGEventServer(TServer):
"""Gevent socket server."""