How to terminate long-running computation (CPU bound task) in Python using asyncio and concurrent.futures.ProcessPoolExecutor?

How do I terminate such long running CPU-bound computations within a method? The approach you tried doesn’t work because the futures returned by ProcessPoolExecutor are not cancellable. Although asyncio’s run_in_executor tries to propagate the cancellation, it is simply ignored by Future.cancel once the task starts executing. There is no fundamental reason for that. Unlike threads, … Read more

Python multiprocessing.Pool: AttributeError

Error 1: AttributeError: Can’t pickle local object ‘SomeClass.some_method..single’ You solved this error yourself by moving the nested target-function single() out to the top-level. Background: Pool needs to pickle (serialize) everything it sends to its worker-processes (IPC). Pickling actually only saves the name of a function and unpickling requires re-importing the function by name. For that … Read more