Commit 9e8bcdc8 authored by Misha Shneerson's avatar Misha Shneerson Committed by Facebook GitHub Bot

FiberManager's shutdown only waits for remote tasks to drain

Reviewed By: andriigrynenko

Differential Revision: D26572552

fbshipit-source-id: 035e1313cd4dec070555b5cd41efc58a0b4a948a
parent 830810d1
...@@ -118,6 +118,10 @@ bool FiberManager::hasTasks() const { ...@@ -118,6 +118,10 @@ bool FiberManager::hasTasks() const {
!remoteTaskQueue_.empty() || remoteCount_ > 0; !remoteTaskQueue_.empty() || remoteCount_ > 0;
} }
bool FiberManager::isRemoteScheduled() const {
return remoteCount_ > 0;
}
Fiber* FiberManager::getFiber() { Fiber* FiberManager::getFiber() {
Fiber* fiber = nullptr; Fiber* fiber = nullptr;
......
...@@ -219,6 +219,7 @@ class FiberManager : public ::folly::Executor { ...@@ -219,6 +219,7 @@ class FiberManager : public ::folly::Executor {
* @return true if there are outstanding tasks. * @return true if there are outstanding tasks.
*/ */
bool hasTasks() const; bool hasTasks() const;
bool isRemoteScheduled() const;
/** /**
* @return The number of currently active fibers (ready to run or blocked). * @return The number of currently active fibers (ready to run or blocked).
......
...@@ -25,7 +25,8 @@ cdef extern from "folly/fibers/FiberManagerInternal.h" namespace "folly::fibers" ...@@ -25,7 +25,8 @@ cdef extern from "folly/fibers/FiberManagerInternal.h" namespace "folly::fibers"
pass pass
cdef cppclass cFiberManager "folly::fibers::FiberManager": cdef cppclass cFiberManager "folly::fibers::FiberManager":
cFiberManager(unique_ptr[cLoopController], const cFiberManagerOptions&) cFiberManager(unique_ptr[cLoopController], const cFiberManagerOptions&)
bool hasTasks() const void loopUntilNoReady()
bool isRemoteScheduled() const
cdef extern from "folly/fibers/ExecutorLoopController.h" namespace "folly::fibers": cdef extern from "folly/fibers/ExecutorLoopController.h" namespace "folly::fibers":
cdef cppclass cAsyncioLoopController "folly::fibers::ExecutorLoopController"(cLoopController): cdef cppclass cAsyncioLoopController "folly::fibers::ExecutorLoopController"(cLoopController):
......
...@@ -44,9 +44,11 @@ cdef class FiberManager: ...@@ -44,9 +44,11 @@ cdef class FiberManager:
opts)); opts));
def __dealloc__(FiberManager self): def __dealloc__(FiberManager self):
while deref(self.cManager).hasTasks(): while deref(self.cManager).isRemoteScheduled():
self.cExecutor.drive() self.cExecutor.drive()
deref(self.cManager).loopUntilNoReady()
# Explicitly reset here, otherwise it is possible # Explicitly reset here, otherwise it is possible
# that self.cManager dstor runs after python finalizes # that self.cManager dstor runs after python finalizes
# Cython deletes these after __dealloc__ returns. # Cython deletes these after __dealloc__ returns.
......
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