All Projects → iximiuz → simple-event-loop

iximiuz / simple-event-loop

Licence: other
Fully-functional Event Loop in 100 Lines of Python

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to simple-event-loop

kwang
High Performance Kotlin Native Web Framework based on Lwan
Stars: ✭ 59 (+13.46%)
Mutual labels:  event-loop
Actor.js
Elixir-style actors in JavaScript
Stars: ✭ 48 (-7.69%)
Mutual labels:  event-loop
Vert.x
Vert.x is a tool-kit for building reactive applications on the JVM
Stars: ✭ 12,544 (+24023.08%)
Mutual labels:  event-loop
Amp
A non-blocking concurrency framework for PHP applications. 🐘
Stars: ✭ 3,457 (+6548.08%)
Mutual labels:  event-loop
Gmq
基于事件机制的多模块框架,支持动态库,grpc,websocket,mqtt等多种与后端通信组合方式. 模块动态替换,部分加载或者升级.
Stars: ✭ 31 (-40.38%)
Mutual labels:  event-loop
Uvw
Header-only, event based, tiny and easy to use libuv wrapper in modern C++ - now available as also shared/static library!
Stars: ✭ 1,222 (+2250%)
Mutual labels:  event-loop
nested scheduler
Shard for creating separate groups of fibers in a hierarchical way and to collect results and errors in a structured way.
Stars: ✭ 20 (-61.54%)
Mutual labels:  event-loop
Blocked At
Detects node eventloop block and reports where it started
Stars: ✭ 219 (+321.15%)
Mutual labels:  event-loop
Uvloop
Ultra fast asyncio event loop.
Stars: ✭ 8,246 (+15757.69%)
Mutual labels:  event-loop
Io uring Echo Server
io_uring echo server
Stars: ✭ 155 (+198.08%)
Mutual labels:  event-loop
Gnet
🚀 gnet is a high-performance, lightweight, non-blocking, event-driven networking framework written in pure Go./ gnet 是一个高性能、轻量级、非阻塞的事件驱动 Go 网络框架。
Stars: ✭ 5,736 (+10930.77%)
Mutual labels:  event-loop
Event Loop
ReactPHP's core reactor event loop that libraries can use for evented I/O.
Stars: ✭ 945 (+1717.31%)
Mutual labels:  event-loop
Eve
An extensible event-driven application framework in haskell
Stars: ✭ 101 (+94.23%)
Mutual labels:  event-loop
reactive-slim
A bridge to use SlimPHP within ReactPHP
Stars: ✭ 25 (-51.92%)
Mutual labels:  event-loop
Event Loop
An event loop interface for interoperability in PHP.
Stars: ✭ 170 (+226.92%)
Mutual labels:  event-loop
nodejs
Node.js in-process collectors for Instana
Stars: ✭ 66 (+26.92%)
Mutual labels:  event-loop
Envelop.c
🌊 Thread-less, event-loop based tiny http-server from scratch using epoll. Learning Purpose.
Stars: ✭ 75 (+44.23%)
Mutual labels:  event-loop
Nest asyncio
Patch asyncio to allow nested event loops
Stars: ✭ 226 (+334.62%)
Mutual labels:  event-loop
Mojo
✨ Mojolicious - Perl real-time web framework
Stars: ✭ 2,298 (+4319.23%)
Mutual labels:  event-loop
Kuma
A network library implemented in C++, supports TCP/UDP/HTTP/HTTP2/WebSocket/SSL on platform Linux/Windows/OSX/iOS/Android.
Stars: ✭ 133 (+155.77%)
Mutual labels:  event-loop

Fully-functional Event Loop in 100 Lines of Python

Check out the series about the event loop on my blog Explain event loop in 100 lines of code and From Callback Hell to async/await Heaven.

Example using callback-style:

import socket as _socket

class EventLoop: pass

class Context: pass

class socket(Context): pass

def main(serv_addr):
    sock = socket(_socket.AF_INET, _socket.SOCK_STREAM)

    def _on_conn(err):
        if err:
            raise err

        def _on_sent(err):
            if err:
                sock.close()
                raise err

            def _on_resp(err, resp=None):
                sock.close()
                if err:
                    raise err
                print(resp)

            sock.recv(1024, _on_resp)

        sock.sendall(b'foobar', _on_sent)

    sock.connect(serv_addr, _on_conn)

if __name__ == '__main__':
    event_loop = EventLoop()
    Context.set_event_loop(event_loop)

    serv_addr = ('127.0.0.1', int(sys.argv[1]))
    event_loop.run(main, serv_addr)

Give it a try:

# server
> python server.py 53210

# client
> python event_loop.py 53210

Example using async-await-like style:

import socket as _socket

class EventLoop: pass

class Context: pass

class socket(Context): pass

def http_get(sock):
  try:
    yield sock.sendall(b'GET / HTTP/1.1\r\nHost: t.co\r\n\r\n')
    return sock.recv(1024)
  finally:
    sock.close()

def main(serv_addr):
  sock = socket(AF_INET, SOCK_STREAM)
  yield sock.connect(serv_addr)
  resp = yield http_get(sock)
  print(resp)

if __name__ == '__main__':
    event_loop = EventLoop()
    Context.set_event_loop(event_loop)

    serv_addr = ('t.co', 80)
    event_loop.run(main)

Give it a try:

> python event_loop_gen.py 53210
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].