Skip to main content

Trace a timeout function call and handle with it

Project description

`中文 <>`__

Check function with timeout for tracing or handle it


- Check a function call is timeout or not.
- The timeout callback and function call are on the same thread.
- Multi-thread support. Nest call support.


.. code:: python

def on_timeout(start_time: float):
:param start_time:
raise Exception("time_out")

# time unit is millisecond
@pymonitor.check_time(10, on_timeout)
def function_1():

def function_2():
with pymonitor.check_context(20, on_timeout):
# do something
with pymonitor.check_context(10, on_timeout):
# do something

Implementation Comparison

Here are some comparisons of the other implementations.

- Use ``signal`` module and emit a signal

- Only works in main thread.
- Not good for nest call becauseof one signal correspond one
If you need nest support you need to enter the timeout function
and call ``alarm``. The cost depend on your accuracy.
- Support Linux only.

- Start new thread for work and join it with a time, if it had timeout,
handle with it (eg. terminate it)

- Can’t inject the function call.
- Overhead from threading.

- Use ``sys.settrace`` keep tracing for each

- A huge cost for that.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for xtimeout, version 0.2.0
Filename, size File type Python version Upload date Hashes
Filename, size xtimeout-0.2.0-cp36-cp36m-win32.whl (322.6 kB) File type Wheel Python version cp36 Upload date Hashes View hashes
Filename, size xtimeout-0.2.0.tar.gz (8.3 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page