Pyjo.Reactor.Asyncio - Low-level event reactor with asyncio support¶
import Pyjo.Reactor.Asyncio
# Watch if handle becomes readable or writable
reactor = Pyjo.Reactor.Asyncio.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.Asyncio is a low-level event reactor based on asyncio.
Pyjo.Reactor.Asyncio will be used as the default backend for
Pyjo.IOLoop if it is loaded before any module using the loop or if
the PYJO_REACTOR environment variable is set to Pyjo.Reactor.Asyncio value.
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
Events¶
Pyjo.Reactor.Asyncio inherits all events from Pyjo.Reactor.Base.
Classes¶
-
class
Pyjo.Reactor.Asyncio.Pyjo_Reactor_Asyncio(**kwargs)¶ Pyjo.Reactor.Asyncioinherits all attributes and methods fromPyjo.Reactor.Baseand implements the following new ones.-
again(tid)¶ reactor.again(tid)
Restart active timer.
-
auto_stop= None¶ - ::
- auto_stop = reactor.auto_stop reactor.auto_stop = False
asyncioloop will be stopped if there is no active I/O or timer events inPyjo.Reactor.Asyncio. This is disabled by default ifloopis provided and enabled otherwise.
-
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.
-
loop= None¶ asyncio_loop = reactor.loop
asyncio main event loop.
-
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.
-
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. Note that this method requires an active I/O watcher.
-
-
Pyjo.Reactor.Asyncio.loop¶ Pyjo.Reactor.Asyncio.loop = asyncio.new_event_loop()
The
asyncioevent loop used by firstPyjo.Reactor.Asyncioobject. The default value isasyncio.get_event_loop().
-
Pyjo.Reactor.Asyncio.object¶ alias of
Pyjo_Reactor_Asyncio