0

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!

picKit
  • 412
  • 1
  • 4
  • 14
  • Maybe this could be helpful to you: https://stackoverflow.com/questions/57031253/how-to-fix-brokenprocesspool-error-for-concurrent-futures-processpoolexecutor – Yohann Boniface May 25 '22 at 08:23
  • How bout putting the kill command inside a try except block, then catch the error and print something like "the process was successfully killed". – Cow May 25 '22 at 08:29
  • `asyncio.run_in_executor()` returns a `Future` so probably `.cancel()`. – Ouroborus May 25 '22 at 08:29

0 Answers0