基于延续的Python Web应用程序框架的设计
java、ruby 等有很多基于延续的框架,但 python 中没有。 Nagare框架在一定程度上解决了这个问题,但它不使用标准python,而是使用stackless python来解决延续问题。
我想知道,
标准 python 约束的哪一部分可以在标准 python 中创建这样的延续 Web 框架?
以及解决方法是什么?延续框架架构中的标准部分是什么(如 MVC 中的模型视图控制器)?
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 framework 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 ) ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您开始考虑编写基于延续的框架之前,您需要一种具有延续的编程语言(或者至少是可用于模拟延续的协同例程)。 Continuation 是一种像循环、闭包或函数这样的控制结构,而不是像 MVC 这样的设计模式。不幸的是(当前)标准 Python 不支持延续。这就是人们开发 stackless python 的原因之一。
Java 是一个比较特殊的例子。语言本身不支持延续,但虚拟机支持(为了支持异常)。我认为他们所做的是在运行时修改编译的字节码并重新排序指令,使其看起来支持延续。有点像通过猴子补丁来实现无堆栈Python。
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.
是的,延续性是语言的一个属性,遗憾的是 CPython 没有延续性。
纯 Python 中的解决方法是众所周知的:例如使用 Twisted 和 Tornado 等回调/延迟器,或者到处使用“yield”来模仿协同例程,例如 Diesel。但这两种方法都迫使您改变设计和编码应用程序的方式。此外,延续可以“重播”,这就是基于延续的框架自动处理“后退”按钮问题的方式。
最后,准确地说,在 Nagare 中,我们使用冻结的微线程的酸洗来获取延续对象。
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.