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

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 RuntimeError

class LockType[source]

Bases: _AtomicBoundedSemaphore

The basic lock type.

Changed in version 24.10.1: Subclassing this object is no longer allowed. This matches the Python 3 API.

Changed in version 24.10.1: No longer accepts arguments to pass to the super class. If you want a semaphore with a different count, use a semaphore class directly. This matches the Lock API of Python 3

acquire(blocking=True, timeout=None) bool[source]

Acquire the semaphore.

Note

If this semaphore was initialized with a value 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, and blocking is true, specifies the maximum amount of seconds this method will block.

Returns:

A bool 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_lock

alias of LockType

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.

get_native_id() integer

Return a non-negative integer identifying the thread as reported by the OS (kernel). This may be used to uniquely identify a particular thread within a system.

interrupt_main(signum=signal.SIGINT, /)

Simulate the arrival of the given signal in the main thread, where the corresponding signal handler will be executed. If signum is omitted, SIGINT is assumed. A subthread can use this function to interrupt the main thread.

Note: the default signal handler for SIGINT raises KeyboardInterrupt.

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.