Don Brown
2014-02-20 07:29:29 UTC
I took another stab at porting Bottle over to asyncio and the fork is found
here:
https://github.com/mrdon/bottle
This lets bottle run fully asynchronous using the new Python standard for
such things. A couple ways this is different than the previous effort [1]:
1. Is a full on fork to get things like run/debug working nicely(ish)
2. Adds before-first-request hook to run setup code as that code will
likely need to run in the event loop
3. Removes all thread locals, opting instead for explicit request/response
objects to handler functions
I made that last change because thread locals don't play nicely with async
code as the different requests handled by the same thread concurrently can
start stepping on each other. There is a way to make such variables
task-local, but it has some limitations, so I went with a more explicit
approach. It makes the functions more noisy but not overly so IMO.
I've started to build apps on this, so I'd like to release it to Pypi. The
current name is Bottle-Async, but I'm happy to change it to something else
or even something w/o bottle in it at all.
Obligatory hello world:
import asyncio
from bottle import Bottle, template
app = Bottle(__name__)
@app.route('/hello/<name>')
@asyncio.coroutine
def index(request, response, name):
yield from asyncio.sleep(1)
return template('<b>Hello {{name}}</b>!', name=name)
app.run(host='localhost', port=8080)
Don
[1] https://groups.google.com/forum/#!topic/bottlepy/saZdaFWZMps
--
here:
https://github.com/mrdon/bottle
This lets bottle run fully asynchronous using the new Python standard for
such things. A couple ways this is different than the previous effort [1]:
1. Is a full on fork to get things like run/debug working nicely(ish)
2. Adds before-first-request hook to run setup code as that code will
likely need to run in the event loop
3. Removes all thread locals, opting instead for explicit request/response
objects to handler functions
I made that last change because thread locals don't play nicely with async
code as the different requests handled by the same thread concurrently can
start stepping on each other. There is a way to make such variables
task-local, but it has some limitations, so I went with a more explicit
approach. It makes the functions more noisy but not overly so IMO.
I've started to build apps on this, so I'd like to release it to Pypi. The
current name is Bottle-Async, but I'm happy to change it to something else
or even something w/o bottle in it at all.
Obligatory hello world:
import asyncio
from bottle import Bottle, template
app = Bottle(__name__)
@app.route('/hello/<name>')
@asyncio.coroutine
def index(request, response, name):
yield from asyncio.sleep(1)
return template('<b>Hello {{name}}</b>!', name=name)
app.run(host='localhost', port=8080)
Don
[1] https://groups.google.com/forum/#!topic/bottlepy/saZdaFWZMps
--
--
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
You are member of the "bottlepy" group at google groups.
See http://groups.google.de/group/bottlepy for mailing list options.
See http://bottlepy.org/ for news and documentation.
---
You received this message because you are subscribed to the Google Groups "bottlepy" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bottlepy+***@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.