async.gevent_engine module¶
-
class
pyrlang.async_support.gevent_engine.
GeventEngine
¶ Bases:
pyrlang.async_support.base_engine.BaseEngine
Compatibility driver for Gevent. Create it before creating Node and pass as argument 'engine' like so:
e = GeventEngine() node = Node(name="py@127.0.0.1", cookie="COOKIE", engine=e)
-
call_later
(t: float, fn)¶ Schedules fn to be called after sleep(t).
-
connect_with
(protocol_class: Type[pyrlang.async_support.base_protocol.BaseProtocol], host_port: tuple, protocol_args: list, protocol_kwargs: dict) -> (<class 'pyrlang.async_support.base_protocol.BaseProtocol'>, <class 'gevent._socket3.socket'>)¶ Helper which creates a new connection and feeds the data stream into a protocol handler class.
Return type: tuple(protocol_class, gevent.socket)
Parameters: - protocol_class -- A handler class which has handler functions like on_connected, consume, and on_connection_lost
- protocol_kwargs -- Keyword args to pass to the handler constructor
- protocol_args -- Args to pass to the handler constructor
- host_port -- (host,port) tuple where to connect
-
destroy
()¶
-
listen_with
(protocol_class: Type[pyrlang.async_support.base_protocol.BaseProtocol], protocol_args: list, protocol_kwargs: dict) -> (<class 'gevent.server.StreamServer'>, <class 'int'>)¶ Spawns a task which would listen on a random port with a given BaseProtocol handler
-
queue_new
() → pyrlang.async_support.base_engine.BaseQueue¶ Create Gevent queue adapter
-
run_forever
()¶ Continues running event loop forever.
-
sleep
(seconds: float)¶ Sleeps given amount of seconds in a nice compatible way.
-
socket_module
()¶ Returns current socket module (modified to be compatible with the current async library). Used functions are: * socket.create_connection * socket.error (Exception class) * socket.gethostbyname
-
spawn
(loop_fn)¶ Spawns a task which will call loop_fn repeatedly while it returns False, else will stop.
-
-
class
pyrlang.async_support.gevent_engine.
GeventQueue
¶ Bases:
pyrlang.async_support.base_engine.BaseQueue
-
get
()¶ Attempt to fetch one item from the queue, or return None.
-
is_empty
()¶
-
put
(v)¶
-
-
pyrlang.async_support.gevent_engine.
make_serve_loop
(protocol_class: Type[pyrlang.async_support.base_protocol.BaseProtocol], protocol_args: list, protocol_kwargs: dict)¶ A basic connection handler that takes an accepted connection and feeds the data stream into the receiver protocol handler class.
Parameters: - protocol_kwargs -- Keyword args to pass to the handler class constructor
- protocol_args -- Args to pass to the handler class constructor
- protocol_class (class) -- A handler class which has handler functions like on_connected, consume, and on_connection_lost
Returns: A handler function suitable for passing to StreamServer