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]: ...@@ -232,7 +232,7 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
cdef libev.ev_timer _periodic_signal_checker cdef libev.ev_timer _periodic_signal_checker
#endif #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 unsigned int c_flags
cdef object old_handler = None cdef object old_handler = None
libev.ev_prepare_init(&self._signal_checker, <void*>gevent_run_callbacks) libev.ev_prepare_init(&self._signal_checker, <void*>gevent_run_callbacks)
...@@ -245,8 +245,10 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]: ...@@ -245,8 +245,10 @@ cdef public class loop [object PyGeventLoopObject, type PyGeventLoop_Type]:
c_flags = _flags_to_int(flags) c_flags = _flags_to_int(flags)
_check_flags(c_flags) _check_flags(c_flags)
c_flags |= libev.EVFLAG_NOENV c_flags |= libev.EVFLAG_NOENV
if _default_loop_destroyed: if default is None:
default = False default = True
if _default_loop_destroyed:
default = False
if default: if default:
self._ptr = libev.gevent_ev_default_loop(c_flags) self._ptr = libev.gevent_ev_default_loop(c_flags)
if not self._ptr: if not self._ptr:
......
...@@ -267,8 +267,8 @@ class Hub(greenlet): ...@@ -267,8 +267,8 @@ class Hub(greenlet):
raise TypeError("Unexpected argument: default") raise TypeError("Unexpected argument: default")
self.loop = loop self.loop = loop
else: else:
if default is None: if default is None and get_ident() != MAIN_THREAD:
default = get_ident() == MAIN_THREAD default = False
loop_class = _import(self.loop_class) loop_class = _import(self.loop_class)
if loop is None: if loop is None:
loop = self.backend loop = self.backend
......
import gevent import gevent
# Loop of initial Hub is default loop.
hub = gevent.get_hub() hub = gevent.get_hub()
assert hub.loop.default, 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() hub = gevent.get_hub()
assert hub.loop.default, hub assert hub.loop.default, hub
# Destroy hub including default loop.
hub.destroy(destroy_loop=True) 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() hub = gevent.get_hub()
assert not hub.loop.default, hub assert not hub.loop.default, hub
hub.destroy() 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