Low-level wrappers around libevent (gevent.core module)
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 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
- Optional object set and read only by the user.
-
callback
User callback that will be called once the event is signalled.
The prototype: callback(event instance, evtype).
-
cancel
- Remove event from the event queue.
-
events
-
events_str
-
fd
-
flags
-
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()
- 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.
-
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
evhttp
-
class gevent.core.http_request
Wrapper around libevent’s evhttp_request structure.
-
chunked
-
connection
-
detach
-
input_buffer
-
kind
-
major
-
minor
-
output_buffer
-
remote
-
remote_host
-
remote_port
- Return True if header was found and removed
- Return True if header was found and removed
-
response
-
response_code
-
response_code_line
-
send_error
-
send_reply
-
send_reply_chunk
-
send_reply_end
-
send_reply_start
-
type
-
typestr
-
uri
-
version
-
class gevent.core.http_connection
-
peer
-
set_closecb
-
class gevent.core.http
-
accept
-
bind
-
set_cb
-
set_gencb
-
start