It's modest attempt to implement the reactor pattern to break the traditional synchronous flow. The event loop uses a single thread and is responsible for scheduling asynchronous operations.
Introduction
In JS event loop is available out of the box. It is working behind the scenes. Asynchronous code in JS looks like this:
setTimeout(() => console.log('world!'), 1000); console.log("Hello ");
the same things with pyreact-event-loop:
loop = event_loop.SelectLoop() loop.add_timer(1, lambda: print("world!")) loop.future_tick(lambda: print("Hello ")) loop.run()
In python needs to explicitly define the event loop.
By standing on the shoulders of Giants
Pyreact-event-loop based on ReactPHP event loop component.
There are three available implementations:
SelectLoopuses theselectmoduleLibevLoopuses themood.eventpythonlibevinterfaceLibuvLoopuses thepyuvpython interface forlibuv
Examples
- timers
- periodic timers
- ticks
- signals
- echo server
- fp streams
- blocking iteration
- non-blocking iteration
How to use
docker build github.com/mapogolions/pyreact-event-loop -t mapogolions/eventloop docker run -it mapogolions/eventloop # ./timers.py # or you could pass a relative file path docker run -it mapogolions/eventloop ./periodic.py docker run -it mapogolions/eventloop ./fp-streams.py