brennivin.ioutils module

Contains utilities for working with IO, such as the retry and timeout decorators, and the is_local_port_open() function.

Also defines Timeout which is used in IO-heavy areas of brennivin.

Members

brennivin.ioutils.is_local_port_open(port)

Returns True if port is open on the local host. Note that this only checks whether the port is open at an instant in time and may be bound after this function checks but before it even returns!

class brennivin.ioutils.retry(attempts=2, excfilter=(<type 'exceptions.Exception'>, ), wait=0, backoff=1, sleepfunc=None)

Decorator used for retrying an operation multiple times. After each retry, the wait will be multiplied by backoff.

Parameters:
  • attempts – Number of attemts to retry, total. Must be >= 1.
  • excfilter – Types of exceptions to catch when an attempt fails.
  • wait – Initial amount of time to sleep before retrying. Must be >= 0. If 0, do not sleep between retries.
  • backoff – Multiplier for time to sleep, multiplied by number of attempts. Must be >= 1.
  • sleepfunc – The function used to sleep between retries. Default to time.sleep().
class brennivin.ioutils.timeout(timeoutSecs=5)

Decorator used for aborting operations after they have timed out. Raises a Timeout on timeout.

The actual work happens on a new thread. Patch the timeout.start_thread method with your own compatible method if you do not want to use a thread to run the operation, such as if you want to use tasklets or greenlets from stackless or gevent.