From da233c46ad7806efb2e4bc21b79d978b51515475 Mon Sep 17 00:00:00 2001 From: Jason Paryani Date: Thu, 7 Jul 2016 12:11:42 -0700 Subject: [PATCH] Make the event loop be lazy initialized Fixes #101 --- capnp/lib/capnp.pyx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/capnp/lib/capnp.pyx b/capnp/lib/capnp.pyx index 5d44e8b..57d675c 100644 --- a/capnp/lib/capnp.pyx +++ b/capnp/lib/capnp.pyx @@ -1638,6 +1638,7 @@ _THREAD_LOCAL_EVENT_LOOPS = [] cdef _EventLoop C_DEFAULT_EVENT_LOOP_GETTER(): 'Optimization for not having to deal with threadlocal event loops unless we need to' + global C_DEFAULT_EVENT_LOOP if C_DEFAULT_EVENT_LOOP is not None: return C_DEFAULT_EVENT_LOOP elif _C_DEFAULT_EVENT_LOOP_LOCAL is not None: @@ -1647,8 +1648,9 @@ cdef _EventLoop C_DEFAULT_EVENT_LOOP_GETTER(): else: _C_DEFAULT_EVENT_LOOP_LOCAL.loop = _EventLoop() return _C_DEFAULT_EVENT_LOOP_LOCAL.loop - - raise KjException("You don't have any EventLoops running. Please make sure to add one") + else: + C_DEFAULT_EVENT_LOOP = _EventLoop() + return C_DEFAULT_EVENT_LOOP cdef class _Timer: cdef capnp.Timer * thisptr