Skip to content

Commit

Permalink
FiberManager's shutdown only waits for remote tasks to drain
Browse files Browse the repository at this point in the history
Reviewed By: andriigrynenko

Differential Revision: D26572552

fbshipit-source-id: 035e1313cd4dec070555b5cd41efc58a0b4a948a
  • Loading branch information
mshneer authored and facebook-github-bot committed Feb 22, 2021
1 parent 830810d commit 9e8bcdc
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 2 deletions.
4 changes: 4 additions & 0 deletions folly/fibers/FiberManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ bool FiberManager::hasTasks() const {
!remoteTaskQueue_.empty() || remoteCount_ > 0;
}

bool FiberManager::isRemoteScheduled() const {
return remoteCount_ > 0;
}

Fiber* FiberManager::getFiber() {
Fiber* fiber = nullptr;

Expand Down
1 change: 1 addition & 0 deletions folly/fibers/FiberManagerInternal.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ class FiberManager : public ::folly::Executor {
* @return true if there are outstanding tasks.
*/
bool hasTasks() const;
bool isRemoteScheduled() const;

/**
* @return The number of currently active fibers (ready to run or blocked).
Expand Down
3 changes: 2 additions & 1 deletion folly/python/fiber_manager.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ cdef extern from "folly/fibers/FiberManagerInternal.h" namespace "folly::fibers"
pass
cdef cppclass cFiberManager "folly::fibers::FiberManager":
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 cppclass cAsyncioLoopController "folly::fibers::ExecutorLoopController"(cLoopController):
Expand Down
4 changes: 3 additions & 1 deletion folly/python/fiber_manager.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ cdef class FiberManager:
opts));

def __dealloc__(FiberManager self):
while deref(self.cManager).hasTasks():
while deref(self.cManager).isRemoteScheduled():
self.cExecutor.drive()

deref(self.cManager).loopUntilNoReady()

# Explicitly reset here, otherwise it is possible
# that self.cManager dstor runs after python finalizes
# Cython deletes these after __dealloc__ returns.
Expand Down

0 comments on commit 9e8bcdc

Please sign in to comment.