bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.45k stars 1.46k forks source link

bottle and monkeyless gevent #374

Open ghost opened 12 years ago

ghost commented 12 years ago

How feasible is it to monkey patch bottle to use gevent/greenlet facilities where applicable rather than rely on gevent's monkey patching of the standard library? while I'm currently using gevent, I also prefer to avoid gevent's monkey patching - I know some people view the convenient monkey patching as part of the point of using gevent, but it does work usefully without it.

Maybe a bottle.gevent_myself() could be added (you're in a better position than me to know what exactly would need patching, but to me it just looks like the _lctx, localproperty and anything using it i.e. LocalRequest/LocalResponse stuff). That way bottle wouldn't need gevent monkey patching to have taken place (or cause it to take place, either i.e. I mean a function that switches bottle over to use greenlet.local etc. where necessary, not a function that just calls gevent.monkey stuff).

defnull commented 12 years ago

Fixing _lctx would do the job for most of bottle. Everything is based on that single thread-local. Only the reloading feature uses threads, sleep, interrupt_main() and such.

So, your idea is feasible, if we can generalize the reloading stuff in a way that is easily switchable between threads and greenlets.