Skip to content

ei-grad/kill-timeout

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Limit the function execution time

This module provides a decorator which runs the function in a separate multiprocessing.Process and sends SIGKILL after the specified timeout if the function didn't complete.

Requirements

  • Python 3.7+ (needed for multiprocessing.Process.kill)
  • tblib (to pass the traceback from separate process)

Install

pip install kill-timeout

Usage

from kill_timeout import kill_timeout


limit_in_seconds = 5


@kill_timeout(limit_in_seconds)
def long_running_function(**parameters):
    """Function which makes some computations

    It could take too long for some parameters.
    """
    ...

try:
    result = long_running_function(iterations=9001)
    print("Function returned: %r" % result)
except TimeoutError:
    print("Function didn't finished in %d seconds" % limit_in_seconds)
except Exception:
    print("Function failed with its internal error! Its original traceback:")
    raise

About

Python library to limit the function execution time

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy