This is a library for network oriented, coroutine based programming.
cogen’s goal is to enable writing code in a seemingly synchronous and easy manner in the form of generators that yield calls and receive the result from that yield. These calls translate to asynchronous and fast os calls in cogen’s internals.
Notable features
a WSGI server, HTTP1.1 compliant, with asynchronous extensions
epoll, kqueue, select, i/o completion ports, sendfile behind the scenes
a couple of useful classes for putting the coroutine to sleep, wait for signals, queues, timeouts etc.
Quick introduction
A coroutine is just a generator wrapped in a helper class:
from cogen.core.coroutines import coroutine
@coroutine
def mycoro(bla):
result = yield <operation>
result = yield <operation>
the operation instructs the scheduler what to do with the coroutine: suspend it till something happens, add another coro in the scheduler, raise a event and so on.
if a operation has a result associated then the yield will return that result (eg. a string or a (connection, address) tuple) otherwise it will return the operation instance.
Echo server example
from cogen.core import sockets
from cogen.core import schedulers
from cogen.core.coroutines import coroutine
@coroutine
def server():
srv = sockets.Socket()
print type(srv)
srv.bind(('localhost',777))
srv.listen(10)
while 1:
print "Listening..."
conn, addr = yield srv.accept()
print "Connection from %s:%s" % addr
m.add(handler, args=(conn, addr))
@coroutine
def handler(sock, addr):
yield sock.write("WELCOME TO ECHO SERVER !\r\n")
while 1:
line = yield sock.readline(8192)
if line.strip() == 'exit':
yield sock.write("GOOD BYE")
sock.close()
return
yield sock.write(line)
m = schedulers.Scheduler()
m.add(server)
m.run()
Documentation
Development
Takes place at: http://code.google.com/p/cogen/
Grab the latest and greatest from trunk with:
easy_install cogen==dev
Metadata
Release files for cogen 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cogen-0.2.1.zip | 348.9 kB | Without provenance | Details for cogen-0.2.1.zip |
Release files / cogen-0.2.1.zip
| Download URL | cogen-0.2.1.zip |
|---|---|
| Size | 348.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c75b4920aece024f820e438c942f3373a76c6ad6e257c557b707436c6978b929
|
|
BLAKE2b-256 checksum How to use checksums |
14aae2f0c43b299840cab45ba2b187b0b876bbe0961fe9ccf41010992091e505
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for cogen 0.2.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.