Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • 1
    This is a life saver for me! My problem was sometimes multiprocessing worker stalled for no reason and was consuming lot of memory and cpu in the sleep state. Tried various wrappers for multiprocessing which has an option for pool timeout but each gave me other different problems like processes not killed after the pool is terminated. Now with this decorator, simply after a long timeout, the function will be killed and the processes spawned inside it. It gives me BrokenPipeError for abruptly closing the pool, but it solved my main problem. Thank you! Any suggestions to handle BrokenPipeError ? Commented Jul 23, 2020 at 7:50
  • 2
    @Arjun Sankarlal : of course if the worker is killed, the pipe will be broken. You need to catch the broken pipe error on the scheduler task and clean up properly. Commented Jul 24, 2020 at 9:05
  • 1
    Yes I understand, and I did in try/except with BrokenPipeError but it was not caught. So I am using it in a webserver. I have a catch for BrokenPipeError and general Exception. So when the timeout occurred, I was returned with general exception not with broken pipe error. But after few seconds, the server printed BrokenPipeError in the console and it server the other requests without any problem. May be I introduce a delay after to check if the pool is broken and then return !? Commented Jul 26, 2020 at 4:09
  • I get a TypeError: cannot pickle 'sqlalchemy.cprocessors.UnicodeResultProcessor'. Tried to use it as timeout for querying a database. version 1.5.1 Commented Jul 1, 2024 at 9:06
  • @ascripter since 'sqlalchemy.cprocessors.UnicodeResultProcessor' is not pickable, reduce the scope of the decorator - use it at the smallest scope possible Commented 14 hours ago