Package pywbem :: Module cim_http :: Class HTTPTimeout

[frames] | no frames]

# Class HTTPTimeout

source code

    object --+
             |
            HTTPTimeout

HTTP timeout class that is a context manager (for use by 'with' statement).

Usage:
  ::
    with HTTPTimeout(timeout, http_conn):
      ... operations using http_conn ...

If the timeout expires, the socket of the HTTP connection is shut down. Once the http operations return as a result of that or for other reasons, the exit handler of this class raises a cim_http.Error exception in the thread that executed the `with` statement.

Instance Methods

__init__(self, timeout, http_conn) Initialize the HTTPTimeout object. | source code

__enter__(self) | source code

__exit__(self, exc_type, exc_value, traceback) | source code

timer_expired(self) This method is invoked in context of the timer thread, so we cannot directly throw exceptions (we can, but they would be in the wrong thread), so instead we shut down the socket of the connection. | source code

Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, timeout, http_conn)
(Constructor)

source code

Initialize the HTTPTimeout object.

Parameters:
  - `timeout` (number) - Timeout in seconds, `None` means no timeout.
  - `http_conn` (`httplib.HTTPBaseConnection` (or subclass)) - The connection that is to be stopped when the timeout expires.
Overrides: object.__init__

### timer_expired(self)

source code

This method is invoked in context of the timer thread, so we cannot directly throw exceptions (we can, but they would be in the wrong thread), so instead we shut down the socket of the connection. When the timeout happens in early phases of the connection setup, there is no socket object on the HTTP connection yet, in that case we retry after the retry duration, indefinitely. So we do not guarantee in all cases that the overall operation times out after the specified timeout.