Pyjo.Reactor.Select - Low-level event reactor with select support¶
import Pyjo.Reactor.Select
# Watch if handle becomes readable or writable
reactor = Pyjo.Reactor.Select.new()
def io_cb(reactor, writable):
if writable:
print('Handle is writable')
else:
print('Handle is readable')
reactor.io(io_cb, handle)
# Change to watching only if handle becomes writable
reactor.watch(handle, read=False, write=True)
# Add a timer
def timer_cb(reactor):
reactor.remove(handle)
print('Timeout!')
reactor.timer(timer_cb, 15)
# Start reactor if necessary
if not reactor.is_running:
reactor.start()
Pyjo.Reactor.Select
is a low-level event reactor based on select.select()
.
Events¶
Pyjo.Reactor.Select
inherits all events from Pyjo.Reactor.Base
.
Debugging¶
You can set the PYJO_REACTOR_DEBUG
environment variable to get some
advanced diagnostics information printed to stderr
.
PYJO_REACTOR_DEBUG=1
You can set the PYJO_REACTOR_DIE
environment variable to make reactor die if task
dies with exception.
PYJO_REACTOR_DIE=1
Classes¶
-
class
Pyjo.Reactor.Select.
Pyjo_Reactor_Select
(**kwargs)¶ Pyjo.Reactor.Select
inherits all attributes and methods fromPyjo.Reactor.Base
and implements the following new ones.-
again
(tid)¶ reactor.again(tid)
Restart active timer.
-
io
(cb, handle)¶ reactor = reactor.io(cb, handle)
Watch handle for I/O events, invoking the callback whenever handle becomes readable or writable.
-
is_running
¶ boolean = reactor.is_running
Check if reactor is running.
-
one_tick
()¶ reactor.one_tick()
Run reactor until an event occurs. Note that this method can recurse back into the reactor, so you need to be careful. Meant to be overloaded in a subclass.
-
recurring
(cb, after)¶ tid = reactor.recurring(cb, 0.25)
Create a new recurring timer, invoking the callback repeatedly after a given amount of time in seconds.
-
remove
(remove)¶ boolean = reactor.remove(handle) boolean = reactor.remove(tid)
Remove handle or timer.
-
reset
()¶ reactor.reset()
Remove all handles and timers.
-
start
()¶ reactor.start()
Start watching for I/O and timer events, this will block until
stop()
is called or there is no any active I/O or timer event.
-
stop
()¶ reactor.stop()
Stop watching for I/O and timer events.
-
timer
(cb, after)¶ tid = reactor.timer(cb, 0.5)
Create a new timer, invoking the callback after a given amount of time in seconds.
-
watch
(handle, read, write)¶ reactor = reactor.watch(handle, read, write)
Change I/O events to watch handle for with true and false values. Meant to be overloaded in a subclass. Note that this method requires an active I/O watcher.
-
-
Pyjo.Reactor.Select.
object
¶ alias of
Pyjo_Reactor_Select