Commit 2b8facde authored by Andrii Grynenko's avatar Andrii Grynenko Committed by Facebook GitHub Bot

Don't discard tasks from executor when draining FiberManager

Summary: FiberManager depends on those tasks to be run to know when it's safe to shut down (i.e. all outstanding tasks should be run).

Differential Revision: D26811875

fbshipit-source-id: 98b59ad28e25e7e47197e23ad3209349fdbfbb44
parent 579e7cb2
......@@ -47,22 +47,9 @@ class AsyncioExecutor : public DrivableExecutor, public SequencedExecutor {
int fileno() const { return consumer_.getFd(); }
void drive() noexcept override {
consumer_.consume([](Func&& func) {
if (FOLLY_DETAIL_PY_ISFINALIZING()) {
// if Python is finalizing calling scheduled functions MAY segfault.
// any code that could have been called is now inconsequential.
return;
}
try {
func();
} catch (...) {
LOG(ERROR) << "Exception thrown by NotificationQueueExecutor task."
<< "Exception message: "
<< folly::exceptionStr(std::current_exception());
}
});
}
void drive() noexcept override { driveImpl(/* canDiscard = */ true); }
void driveNoDiscard() noexcept { driveImpl(/* canDiscard = */ false); }
protected:
bool keepAliveAcquire() noexcept override {
......@@ -79,6 +66,23 @@ class AsyncioExecutor : public DrivableExecutor, public SequencedExecutor {
}
private:
void driveImpl(bool canDiscard) noexcept {
consumer_.consume([&](Func&& func) {
if (canDiscard && FOLLY_DETAIL_PY_ISFINALIZING()) {
// if Python is finalizing calling scheduled functions MAY segfault.
// any code that could have been called is now inconsequential.
return;
}
try {
func();
} catch (...) {
LOG(ERROR) << "Exception thrown by NotificationQueueExecutor task."
<< "Exception message: "
<< folly::exceptionStr(std::current_exception());
}
});
}
folly::NotificationQueue<Func> queue_;
folly::NotificationQueue<Func>::SimpleConsumer consumer_{queue_};
std::atomic<size_t> keepAliveCounter_{1};
......
# Copyright (c) Facebook, Inc. and its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# distutils: language = c++
from libcpp.memory cimport unique_ptr
......@@ -7,6 +21,7 @@ cdef extern from "folly/python/AsyncioExecutor.h" namespace "folly::python":
cdef cppclass cAsyncioExecutor "folly::python::AsyncioExecutor"(cFollyExecutor):
int fileno()
void drive()
void driveNoDiscard()
cdef class AsyncioExecutor:
cdef unique_ptr[cAsyncioExecutor] cQ
......
......@@ -45,7 +45,7 @@ cdef class FiberManager:
def __dealloc__(FiberManager self):
while deref(self.cManager).isRemoteScheduled():
self.cExecutor.drive()
self.cExecutor.driveNoDiscard()
deref(self.cManager).loopUntilNoReady()
......
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