pyos / h2py Goto Github PK
View Code? Open in Web Editor NEWPython bindings for H2O's server-related stuff.
Home Page: https://github.com/h2o/h2o
Python bindings for H2O's server-related stuff.
Home Page: https://github.com/h2o/h2o
If the request handler spawns an async task to respond to that request, the next request on the same connection may be delayed for up to 10 seconds for some reason:
# server.py
import asyncio
import signal
import socket
import sys
import aiouv
import h2py
@asyncio.coroutine
def onrequest(req):
try:
return req.respond(200, [('content-length', '5')], 'OK', b'test\n')
except ConnectionError:
pass
sock = socket.socket()
sock.bind(('', 8000))
sock.setblocking(False)
loop = aiouv.EventLoop()
loop.add_signal_handler(signal.SIGINT, exit)
serv = h2py.Server([sock.detach()], loop._loop, lambda io: asyncio.async(onrequest(io), loop=loop))
try:
loop.run_forever()
finally:
serv.close()
# client.py
import socket
sock = socket.socket()
sock.connect(('127.0.0.1', 8000))
sock.sendall(b'''GET / HTTP/1.1\r\n\r
GET / HTTP/1.1\r\n\r
GET / HTTP/1.1\r\n\r
GET / HTTP/1.1\r\n\r
''')
try:
while True:
print(sock.recv(2048).decode('utf-8'))
except KeyboardInterrupt:
pass
finally:
sock.close()
$ python server.py &
$ python client.py
HTTP/1.1 200 OK
...
[ 6 seconds pass ]
HTTP/1.1 200 OK
...
This does not affect clients on different connections, and also resolves itself if requests are handled as soon as they arrive:
...
serv = h2py.Server([sock.detach()], loop._loop, lambda io: list(onrequest(io)))
...
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.