サーバーに telnet で接続しようとすると、コードがprint 'never reach1'
or行に到達しません。print 'never reach2'
import sys, signal
from gevent.server import StreamServer
from gevent.pool import Pool
from gevent import monkey
import gevent
from gevent import Timeout
import random
class SocketPool(object):
def __init__(self):
self.pool = Pool(1000)
def listen(self, socket):
while True:
line = socket.recv(1024)
print line
def add_handler(self, socket, address):
if self.pool.full():
raise Exception("At maximum pool size")
else:
self.pool.spawn(self.listen, socket)
gevent.spawn(self.wait).join()
def wait(self):
try:
timeout = Timeout(1)
timeout.start()
except Timeout:
print 'never reach1'
except:
print 'never reach2'
def shutdown(self): self.pool.kill()
def signal_handler(signal, frame): sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
monkey.patch_all()
sockPool = SocketPool()
server = StreamServer(('127.0.0.1', 5000), sockPool.add_handler)
server.serve_forever()