design for continuation based python web appliction framework
There are many continuation based framework for java, ruby etc but none in python. Nagare framework somewhat solves the problem but it do not use standard python and uses stackless python to solve continuation problem.
I was wondering,
what part of standard python constraint to create such continuation web framew开发者_C百科ork in standard python ?
and What are the workaround to it ? and what are standard part in continuation framework architecture ( as model view controller are in MVC ) ?
Before you can even begin to consider writing a continuation based framework you need a programming language that has continuations (or at least co-routines which can be used to emulate continuations). Continuation is a control structure like loops or closures or functions, not a design pattern like MVC. Unfortunately the (currently) standard Python does not support continuations. Which is one of the reason people developed stackless python.
Java is a bit of a special case. The language itself does not support continuations but the virtual machine does (in order to support exceptions). I think what they did was to modify the compiled bytecode at runtime and re-order instructions so that it looks like it supports continuations. Kind of like implementing stackless python by monkey-patching.
Right, continuation is a property of a language and CPython sadly has not continuations.
The workarounds in pure Python are well known : use callbacks / deferers like Twisted and Tornado for example or use 'yield' everywhere to mimic co-routines, like Diesel. But both approaches force you to change the way you design and code your application. Also a continuation can be "replayed" which is how the continuation based frameworks automatically handle the "back" button problem.
Finally, to be exact, in Nagare we are using the pickling of a freezed tasklet to obtain a continuation object.
精彩评论