Commit 7672324a authored by Matthieu Martin's avatar Matthieu Martin Committed by Facebook Github Bot

Add FiberManager::Options parameter to folly::python::getFiberManager

Summary:
Copied the `const folly::fibers::FiberManager::Options& opts = {}` signature from main `getFiberManager`.
Discussed with Andrii if I should key the FiberManager cache by options' address, but he voted to keep the behavior consistent with FiberManagerMap.

Reviewed By: andriigrynenko

Differential Revision: D7873868

fbshipit-source-id: 0c7f6e6ef0ebe50d9658c2eee7ab1e098dd86ddd
parent 0a511014
...@@ -6,15 +6,13 @@ cdef extern from "folly/fibers/LoopController.h" namespace "folly::fibers": ...@@ -6,15 +6,13 @@ cdef extern from "folly/fibers/LoopController.h" namespace "folly::fibers":
pass pass
cdef extern from "folly/fibers/FiberManagerInternal.h" namespace "folly::fibers": cdef extern from "folly/fibers/FiberManagerInternal.h" namespace "folly::fibers":
cdef cppclass cFiberManagerOptions "folly::fibers::FiberManager::Options":
pass
cdef cppclass cFiberManager "folly::fibers::FiberManager": cdef cppclass cFiberManager "folly::fibers::FiberManager":
cFiberManager(unique_ptr[cLoopController]) cFiberManager(unique_ptr[cLoopController], const cFiberManagerOptions&)
cdef extern from "folly/python/AsyncioLoopController.h" namespace "folly::python": cdef extern from "folly/python/AsyncioLoopController.h" namespace "folly::python":
cdef cppclass cAsyncioLoopController "folly::python::AsyncioLoopController"(cLoopController): cdef cppclass cAsyncioLoopController "folly::python::AsyncioLoopController"(cLoopController):
cAsyncioLoopController(cAsyncioExecutor*) cAsyncioLoopController(cAsyncioExecutor*)
cdef class FiberManager: cdef api cFiberManager* get_fiber_manager(const cFiberManagerOptions&)
cdef unique_ptr[cFiberManager] cManager
cdef api cFiberManager* get_fiber_manager()
import asyncio import asyncio
from libcpp.memory cimport unique_ptr from libcpp.memory cimport unique_ptr
from folly.executor cimport get_executor from folly.executor cimport get_executor
from folly.fiber_manager cimport cFiberManager, cLoopController, cAsyncioLoopController from folly.fiber_manager cimport (
cFiberManager,
cLoopController,
cAsyncioLoopController,
cFiberManagerOptions)
from weakref import WeakKeyDictionary from weakref import WeakKeyDictionary
#asynico Loops to FiberManager #asynico Loops to FiberManager
...@@ -9,17 +13,22 @@ loop_to_controller = WeakKeyDictionary() ...@@ -9,17 +13,22 @@ loop_to_controller = WeakKeyDictionary()
cdef class FiberManager: cdef class FiberManager:
def __cinit__(self): cdef unique_ptr[cFiberManager] cManager
# Lazy constructor, as __cinit__ doesn't support C types
cdef init(self, const cFiberManagerOptions& opts):
self.cManager.reset(new cFiberManager( self.cManager.reset(new cFiberManager(
unique_ptr[cLoopController](new cAsyncioLoopController( unique_ptr[cLoopController](new cAsyncioLoopController(
get_executor())))); get_executor())),
opts));
cdef cFiberManager* get_fiber_manager(): cdef cFiberManager* get_fiber_manager(const cFiberManagerOptions& opts):
loop = asyncio.get_event_loop() loop = asyncio.get_event_loop()
try: try:
manager = <FiberManager>(loop_to_controller[loop]) manager = <FiberManager>(loop_to_controller[loop])
except KeyError: except KeyError:
manager = FiberManager() manager = FiberManager()
manager.init(opts)
loop_to_controller[loop] = manager loop_to_controller[loop] = manager
return manager.cManager.get() return manager.cManager.get()
...@@ -14,7 +14,7 @@ ...@@ -14,7 +14,7 @@
* limitations under the License. * limitations under the License.
*/ */
/* /*
* This file serves as a helper for bridging folly::future and python * This file serves as a helper for bridging folly fibers and python
* asyncio.future. * asyncio.future.
*/ */
...@@ -28,9 +28,10 @@ ...@@ -28,9 +28,10 @@
namespace folly { namespace folly {
namespace python { namespace python {
inline folly::fibers::FiberManager* getFiberManager() { inline folly::fibers::FiberManager* getFiberManager(
const folly::fibers::FiberManager::Options& opts = {}) {
import_folly__fiber_manager(); import_folly__fiber_manager();
return get_fiber_manager(); return get_fiber_manager(opts);
} }
/** /**
......
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