# gevent

# `gevent.thread` – Implementation of the standard `thread` module that spawns greenlets

Note

This module is a helper for `gevent.monkey` and is not intended to be used directly. For spawning greenlets in your applications, prefer higher level constructs like `gevent.Greenlet` class or `gevent.spawn()`.

`error`

  alias of `builtins.RuntimeError`

`allocate_lock`

  alias of `gevent.thread.LockType`

class `LockType`(*args, **kwargs)

  Bases: `gevent._semaphore.BoundedSemaphore`

  `acquire`(blocking=True, timeout=None) → bool

    Acquire the semaphore.

    Caution

    If this semaphore was initialized with a size of 0, this method will block forever (unless a timeout is given or blocking is set to false).

    Parameters:

    - blocking (bool) – If True (the default), this function will block until the semaphore is acquired.
    - timeout (float) – If given, specifies the maximum amount of seconds this method will block.

    Returns:

    A boolean indicating whether the semaphore was acquired. If `blocking` is True and `timeout` is None (the default), then (so long as this semaphore was initialized with a size greater than 0) this will always return True. If a timeout was given, and it expired before the semaphore was acquired, False will be returned. (Note that this can still raise a `Timeout` exception, if some other caller had already started a timer.)

`allocate`()

  allocate_lock() -> lock object (allocate() is an obsolete synonym)

  Create a new lock object. See help(type(threading.Lock())) for information about locks.

`exit_thread`()

  exit() (exit_thread() is an obsolete synonym)

  This is synonymous to ``raise SystemExit’’. It will cause the current thread to exit silently unless the exception is caught.

`interrupt_main`()

  Raise a KeyboardInterrupt in the main thread. A subthread can use this function to interrupt the main thread.

`start_new`()

  start_new_thread(function, args[, kwargs]) (start_new() is an obsolete synonym)

  Start a new thread and return its identifier. The thread will call the function with positional arguments from the tuple args and keyword arguments taken from the optional dictionary kwargs. The thread exits when the function returns; the return value is ignored. The thread will also exit when the function raises an unhandled exception; a stack trace will be printed unless the exception is SystemExit.

Next page: `gevent.threading` – Implementation of the standard `threading` using greenlets