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