Should gevent's fork create a new hub in its forked process?

93 views
Skip to first unread message

Liming Zhao

unread,
May 11, 2012, 1:16:16 PM5/11/12
to gevent: coroutine-based Python network library
using gevent/1.0b2, greenlet/0.3.4

import os
from gevent.hub import fork, get_hub
print 'parent_pid=%d, hub=%s' % (os.getpid(), get_hub())
pid = fork()
if not pid:
# child
print 'child_pid=%d, hub=%s' % (os.getpid(), get_hub())
os._exit(0)
print 'parent_pid=%d, hub=%s' % (os.getpid(), get_hub())

PRINTS:

parent_pid=19326, hub=<Hub at 0x19d92eb0 epoll default pending=0 ref=0
fileno=3>
child_pid=19327, hub=<Hub at 0x19d92eb0 epoll default pending=0 ref=0
fileno=3>
parent_pid=19326, hub=<Hub at 0x19d92eb0 epoll default pending=0 ref=0
fileno=3>

If hub is said to be thread local, should subprocess have its own hub
or not?

Thanks!

Damjan

unread,
May 11, 2012, 2:07:16 PM5/11/12
to gev...@googlegroups.com
Well, fork creates processes not threads. So the object could have the same id, but still exists in separate kemory spaces.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages