gevent.core - Low-level wrappers around libevent

This module provides a mechanism to execute a function when a specific event on a file handle, file descriptor, or signal occurs, or after a given time has passed. It also provides wrappers around structures and functions from libevent-dns and libevent-http.

This module does not work with the greenlets. A callback passed to a method from this module will be executed in the event loop, which is running in the Hub greenlet. Therefore it must not use any synchronous gevent API, that is, the functions that switch to the Hub. It’s OK to call asynchronous stuff like gevent.spawn(), Event.set <gevent.event.Event.set() or Queue.put_nowait.

The code is based on pyevent.

events

class gevent.core.event(evtype, handle, callback[, arg])

Create a new event object with a user callback.

  • evtype – bitmask of EV_READ or EV_WRITE, or EV_SIGNAL
  • handle – a file handle, descriptor, or socket for EV_READ or EV_WRITE; a signal number for EV_SIGNAL
  • callback – user callback with (event, evtype) prototype
  • arg – optional object, which will be made available as arg property.
add()

Add event to be executed after an optional timeout - number of seconds after which the event will be executed.

arg
callback
cancel()

Remove event from the event queue.

events
events_str
fd
flags
flags_str
pending

Return True if the event is still scheduled to run.

class gevent.core.read_event

Create a new scheduled event with evtype=EV_READ

class gevent.core.write_event

Create a new scheduled event with evtype=EV_WRITE

class gevent.core.timer

Create a new scheduled timer

class gevent.core.signal

Create a new persistent signal event

class gevent.core.active_event

An event that is scheduled to run in the current loop iteration

add()

event loop

gevent.core.init()

Initialize event queue.

gevent.core.dispatch()

Dispatch all events on the event queue. Returns 0 on success, and 1 if no events are registered. May raise IOError.

gevent.core.loop()

Dispatch all pending events on queue in a single pass. Returns 0 on success, and 1 if no events are registered. May raise IOError.

gevent.core.get_version()

Wrapper for event_get_version()

gevent.core.get_method()

Wrapper for event_get_method()

gevent.core.get_header_version()

Return _EVENT_VERSION

evdns

gevent.core.dns_init()

Initialize async DNS resolver.

gevent.core.dns_shutdown()

Shutdown the async DNS resolver and terminate all active requests.

gevent.core.dns_resolve_ipv4()

Lookup an A record for a given name.

  • name – DNS hostname
  • flags – either 0 or DNS_QUERY_NO_SEARCH
  • callback – callback with (result, type, ttl, addrs) prototype
gevent.core.dns_resolve_ipv6()

Lookup an AAAA record for a given name.

  • name – DNS hostname
  • flags – either 0 or DNS_QUERY_NO_SEARCH
  • callback – callback with (result, type, ttl, addrs) prototype
gevent.core.dns_resolve_reverse()

Lookup a PTR record for a given IPv4 address.

  • packed_ip – IPv4 address (as 4-byte binary string)
  • flags – either 0 or DNS_QUERY_NO_SEARCH
  • callback – callback with (result, type, ttl, addrs) prototype
gevent.core.dns_resolve_reverse_ipv6()

Lookup a PTR record for a given IPv6 address.

  • packed_ip – IPv6 address (as 16-byte binary string)
  • flags – either 0 or DNS_QUERY_NO_SEARCH
  • callback – callback with (result, type, ttl, addrs) prototype

evbuffer

class gevent.core.buffer

file-like wrapper for libevent’s evbuffer structure.

Note, that the wrapper does not own the structure, libevent does.

detach()
next

x.next() -> the next value, or raise StopIteration

read()

Drain the first size bytes from the buffer (or what’s left if there are less than size bytes).

If size is negative, drain the whole buffer.

readline()
readlines()
write()

evhttp

class gevent.core.http_request

Wrapper around libevent’s evhttp_request structure.

default_response_headers
send_error()
send_reply()
send_reply_chunk()
send_reply_end()
send_reply_start()
class gevent.core.http_connection
make_request()
static new()
peer
set_local_address()
set_retries()
set_timeout()
class gevent.core.http
accept()
bind()
default_response_headers
handle

Table Of Contents

Previous topic

gevent.wsgi

Next topic

Changelog