I have an asyncio powered project. I have a process function which starts every time I need via asyncio.run_in_executor()
function.
Here's my function:
def fn():
print(f"run: {os.getpid()}")
def __kill_itself():
print(f"kill itself: {os.getpid()}")
os.system(f"kill {os.getpid()}")
...
Once I need to stop my process kill_itself
will be called. But this way raises the BrokenProcessPool
exception. After that executor becomes unusable.
concurrent.futures.process.BrokenProcessPool: A process in the process pool was terminated abruptly while the future was running or pending
What is the correct way to stop a process by itself? Thanks in advance!