Skip to content

AntoineCezar/timeoutcontext

Repository files navigation

Timeoutcontext

A signal based timeout context manager and decorator.

Since it is signal based this package can not work under Windows operating system.

Usage

As a context manager:

import sys
from time import sleep
from timeoutcontext import timeout
if sys.version_info < (3, 3):
    from timeoutcontext._timeout import TimeoutError

try:
    with timeout(1):
        sleep(2)
except TimeoutError:
    print('timeout')

As a decorator:

import sys
from time import sleep
from timeoutcontext import timeout
if sys.version_info < (3, 3):
    from timeoutcontext._timeout import TimeoutError

@timeout(1)
def wait():
    sleep(2)

try:
    wait()
except TimeoutError:
    print('timeout')

License

  • Free software: BSD license

About

A signal based timeout context manager and decorator.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •