gevent 1.0rc fork several threads that listens on one port

79 views
Skip to first unread message

jsia

unread,
Feb 14, 2013, 3:41:31 AM2/14/13
to gev...@googlegroups.com

I was using this on the old gevent with libevent to fork several threads that listens on one port

  address = "0.0.0.0", 8000
    server = WSGIServer(address, application)
    server.pre_start()
    for i in range(10):
        pid = gevent.hub.fork()
        if pid == 0:
            break

    try:
        server.serve_forever()
    except KeyboardInterrupt:
        server.stop()
  

How can it be done on the gevent 1.0rc?


Thanks,

Jason

Håkan Rosenhorn

unread,
Feb 14, 2013, 4:37:00 AM2/14/13
to gev...@googlegroups.com
Hi,

This is how i have been doing it and it still seems to work with 1.0rc2

port = 8000
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(("0.0.0.0", port)) 

for i in range(10):
    pid = os.fork()
    if pid == 0:
        break

address = socket.fromfd(sock.fileno(), socket.AF_INET, socket.SOCK_STREAM)
address.listen(10)
server = WSGIServer(address, application, log=None)
server.serve_forever()

/Håkan

2013/2/14 jsia <jsi...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "gevent: coroutine-based Python network library" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gevent+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

jsia

unread,
Feb 14, 2013, 9:14:39 PM2/14/13
to gev...@googlegroups.com, ha...@esn.me
Hi,

    Thanks for the reply.  It works.  I also found out that replacing pre_start with init_socket() will also make it work.  I think they've changed the function name from pre_start to init_socket.  The function checks if the socket is already initiated. 

Jason


Reply all
Reply to author
Forward
0 new messages