Commit 5840d67a authored by Matthieu Martin's avatar Matthieu Martin Committed by Facebook Github Bot

Rename NotificationQueueExecutor to AsyncioExecutor

Summary:
And move it to folly::python namespace.
We are going to make the python bridge work with fibers. This will require to make changes to this executor that are quite specific for the python use case.
It doesn't hurt to remove YetAnotherExecutor choice from the main executor directory.

Reviewed By: yfeldblum

Differential Revision: D7811125

fbshipit-source-id: eec21ccbbbad58aaa795df661ba58f67fa177645
parent 32e28492
...@@ -109,7 +109,6 @@ nobase_follyinclude_HEADERS = \ ...@@ -109,7 +109,6 @@ nobase_follyinclude_HEADERS = \
executors/IOExecutor.h \ executors/IOExecutor.h \
executors/IOObjectCache.h \ executors/IOObjectCache.h \
executors/IOThreadPoolExecutor.h \ executors/IOThreadPoolExecutor.h \
executors/NotificationQueueExecutor.h \
executors/QueuedImmediateExecutor.h \ executors/QueuedImmediateExecutor.h \
executors/ScheduledExecutor.h \ executors/ScheduledExecutor.h \
executors/SequencedExecutor.h \ executors/SequencedExecutor.h \
......
...@@ -22,9 +22,9 @@ ...@@ -22,9 +22,9 @@
#include <folly/io/async/NotificationQueue.h> #include <folly/io/async/NotificationQueue.h>
namespace folly { namespace folly {
namespace python {
class NotificationQueueExecutor : public DrivableExecutor, class AsyncioExecutor : public DrivableExecutor, public SequencedExecutor {
public SequencedExecutor {
public: public:
using Func = folly::Func; using Func = folly::Func;
...@@ -42,11 +42,11 @@ class NotificationQueueExecutor : public DrivableExecutor, ...@@ -42,11 +42,11 @@ class NotificationQueueExecutor : public DrivableExecutor,
try { try {
func(); func();
} catch (const std::exception& ex) { } catch (const std::exception& ex) {
LOG(ERROR) << "Exception thrown by NotificationQueueExecutor task." LOG(ERROR) << "Exception thrown by AsyncioExecutor task."
<< "Exception message: " << folly::exceptionStr(ex); << "Exception message: " << folly::exceptionStr(ex);
} catch (...) { } catch (...) {
LOG(ERROR) << "Unknown Exception thrown " LOG(ERROR) << "Unknown Exception thrown "
<< "by NotificationQueueExecutor task."; << "by AsyncioExecutor task.";
} }
} }
} }
...@@ -54,6 +54,7 @@ class NotificationQueueExecutor : public DrivableExecutor, ...@@ -54,6 +54,7 @@ class NotificationQueueExecutor : public DrivableExecutor,
private: private:
folly::NotificationQueue<Func> queue_; folly::NotificationQueue<Func> queue_;
folly::NotificationQueue<Func>::SimpleConsumer consumer_{queue_}; folly::NotificationQueue<Func>::SimpleConsumer consumer_{queue_};
}; // NotificationQueueExecutor }; // AsyncioExecutor
} // namespace python
} // namespace folly } // namespace folly
from libcpp.memory cimport unique_ptr from libcpp.memory cimport unique_ptr
from folly cimport cFollyExecutor from folly cimport cFollyExecutor
cdef extern from "folly/executors/NotificationQueueExecutor.h" namespace "folly": cdef extern from "folly/python/AsyncioExecutor.h" namespace "folly::python":
cdef cppclass cNotificationQueueExecutor "folly::NotificationQueueExecutor"(cFollyExecutor): cdef cppclass cAsyncioExecutor "folly::python::AsyncioExecutor"(cFollyExecutor):
int fileno() int fileno()
void drive() void drive()
cdef class NotificationQueueExecutor: cdef class AsyncioExecutor:
cdef unique_ptr[cNotificationQueueExecutor] cQ cdef unique_ptr[cAsyncioExecutor] cQ
cdef api cFollyExecutor* get_executor() cdef api cFollyExecutor* get_executor()
import asyncio import asyncio
from folly cimport cFollyExecutor from folly cimport cFollyExecutor
from folly.executor cimport cNotificationQueueExecutor 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 NotificationQueueExecutor #asynico Loops to AsyncioExecutor
loop_to_q = WeakKeyDictionary() loop_to_q = WeakKeyDictionary()
cdef class NotificationQueueExecutor: cdef class AsyncioExecutor:
def __cinit__(self): def __cinit__(self):
self.cQ = make_unique[cNotificationQueueExecutor](); self.cQ = make_unique[cAsyncioExecutor]();
def fileno(NotificationQueueExecutor self): def fileno(AsyncioExecutor self):
return deref(self.cQ).fileno() return deref(self.cQ).fileno()
def drive(NotificationQueueExecutor self): def drive(AsyncioExecutor self):
deref(self.cQ).drive() deref(self.cQ).drive()
def __dealloc__(NotificationQueueExecutor self): def __dealloc__(AsyncioExecutor self):
# We drive it one last time # We drive it one last time
deref(self.cQ).drive() deref(self.cQ).drive()
...@@ -27,9 +27,9 @@ cdef class NotificationQueueExecutor: ...@@ -27,9 +27,9 @@ cdef class NotificationQueueExecutor:
cdef cFollyExecutor* get_executor(): cdef cFollyExecutor* get_executor():
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
try: try:
Q = <NotificationQueueExecutor>(loop_to_q[loop]) Q = <AsyncioExecutor>(loop_to_q[loop])
except KeyError: except KeyError:
Q = NotificationQueueExecutor() Q = AsyncioExecutor()
loop.add_reader(Q.fileno(), Q.drive) loop.add_reader(Q.fileno(), Q.drive)
loop_to_q[loop] = Q loop_to_q[loop] = Q
return Q.cQ.get() return Q.cQ.get()
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