Commit 9a34add5 authored by Jason Fried's avatar Jason Fried Committed by Facebook Github Bot

Don't raise ignored exception return nullptr instead

Summary:
Sometimes get_executor gets called from threads where there is no asyncio evenloop.
In those cases return NULL.

The caller is responsible for this situation.

Reviewed By: yfeldblum

Differential Revision: D8492709

fbshipit-source-id: 325689ecd4541b9ba097cfe1cb4d6d61ad81cb43
parent 64eca5b8
import asyncio import asyncio
from folly.executor cimport cAsyncioExecutor from folly.executor cimport cAsyncioExecutor
from libcpp.memory cimport make_unique, unique_ptr from libcpp.memory cimport make_unique, unique_ptr
from cython.operator cimport dereference as deref from cython.operator cimport dereference as deref
from weakref import WeakKeyDictionary from weakref import WeakKeyDictionary
#asynico Loops to AsyncioExecutor # asyncio Loops to AsyncioExecutor
loop_to_q = WeakKeyDictionary() loop_to_q = WeakKeyDictionary()
cdef class AsyncioExecutor: cdef class AsyncioExecutor:
def __cinit__(self): def __cinit__(self):
self.cQ = make_unique[cAsyncioExecutor](); self.cQ = make_unique[cAsyncioExecutor]()
def fileno(AsyncioExecutor self): def fileno(AsyncioExecutor self):
return deref(self.cQ).fileno() return deref(self.cQ).fileno()
...@@ -24,7 +25,10 @@ cdef class AsyncioExecutor: ...@@ -24,7 +25,10 @@ cdef class AsyncioExecutor:
cdef cAsyncioExecutor* get_executor(): cdef cAsyncioExecutor* get_executor():
try:
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
except RuntimeError:
return NULL
try: try:
Q = <AsyncioExecutor>(loop_to_q[loop]) Q = <AsyncioExecutor>(loop_to_q[loop])
except KeyError: except KeyError:
......
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