Commit 6be07546 authored by Jan-Philip Gehrcke's avatar Jan-Philip Gehrcke Committed by Denis Bilenko

Allow for explicit default loop creation via `get_hub(default=True)` after...

Allow for explicit default loop creation via `get_hub(default=True)` after default loop destruction. Include unit test.
parent 2af9eee1
......@@ -232,7 +232,7 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
cdef libev.ev_timer _periodic_signal_checker
#endif
def __init__(self, object flags=None, object default=True, size_t ptr=0):
def __init__(self, object flags=None, object default=None, size_t ptr=0):
cdef unsigned int c_flags
cdef object old_handler = None
libev.ev_prepare_init(&self._signal_checker, <void*>gevent_run_callbacks)
......@@ -245,6 +245,8 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
c_flags = _flags_to_int(flags)
_check_flags(c_flags)
c_flags |= libev.EVFLAG_NOENV
if default is None:
default = True
if _default_loop_destroyed:
default = False
if default:
......
......@@ -267,8 +267,8 @@ class Hub(greenlet):
raise TypeError("Unexpected argument: default")
self.loop = loop
else:
if default is None:
default = get_ident() == MAIN_THREAD
if default is None and get_ident() != MAIN_THREAD:
default = False
loop_class = _import(self.loop_class)
if loop is None:
loop = self.backend
......
import gevent
# Loop of initial Hub is default loop.
hub = gevent.get_hub()
assert hub.loop.default, hub
hub.destroy()
# Destroy hub. Does not destroy default loop if not explicitly told to.
hub.destroy()
hub = gevent.get_hub()
assert hub.loop.default, hub
# Destroy hub including default loop.
hub.destroy(destroy_loop=True)
# Create new hub and explicitly request creation of a new default loop.
hub = gevent.get_hub(default=True)
assert hub.loop.default, hub
# Destroy hub including default loop.
hub.destroy(destroy_loop=True)
# Create new non-default loop in new hub.
hub = gevent.get_hub()
assert not hub.loop.default, hub
hub.destroy()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment