The Essentials Of Stackless Python

上传人:jiups****uk12 文档编号:57182547 上传时间:2018-10-19 格式:PPT 页数:25 大小:207KB
返回 下载 相关 举报
The Essentials Of Stackless Python_第1页
第1页 / 共25页
The Essentials Of Stackless Python_第2页
第2页 / 共25页
The Essentials Of Stackless Python_第3页
第3页 / 共25页
The Essentials Of Stackless Python_第4页
第4页 / 共25页
The Essentials Of Stackless Python_第5页
第5页 / 共25页
点击查看更多>>
资源描述

《The Essentials Of Stackless Python》由会员分享,可在线阅读,更多相关《The Essentials Of Stackless Python(25页珍藏版)》请在金锄头文库上搜索。

1、The Essentials Of Stackless Python,or: this is the real thing!,A Note About Hardware,Hardware matters. I learned that after suffering from Stroke since last June Sorry, no interactive session today Fingers are still learning to tyzpe Ok, maybe we do a little bit Restored my brain from backups :-)The

2、 show must go on,Stackless as we know it,Uses tasklets to encapsulate threads of execution Uses channels for control flow between tasklets (ok, also schedule() ) No direct switching No naming of jump targets Learned that from Limbo language http:/ in C Minimal patch Cooperative switching (soft) Brut

3、e-force switching (hard),1) Hard Switching,Very powerful Hard to know when switching is allowed Not too fast (10 x faster than threads) Requires assembly GC problems No pickling possible,2) Soft switching,The real thing No assembly Ultra-fast (at least 100 x faster than threads) At the order of a ge

4、nerator calls speed Pickling possible But hard to implement Needs writing stackless style in C (ugly) Unwind the stack Avoid recursive interpreter call Lots of changes to CPython,Show it?,The CPython Compromize,C-Stackless uses 90 % soft switching Implemented support for the most commonly used funct

5、ions only Patching about 5 % of all functions The rest is still hard switching PyPy has shown that 50% needs to change for a complete soft implementation This will probably not happen The compromize works fine,PyPy: the real Stackless,Stackless transform Built into the translation chain Stack unwind

6、ing under the hood 100 % soft switching Relief: never have to write stackless style again :-) Stackless features available at low-level Coroutines at C level possible,Stackless RPython,Acts like a C compiler that knows how to unwind/restore Convenient, almost pythonic language Has a built-in primiti

7、ve coroutine implementation. Coroutines on application level are built on top of RPython coroutines,Is That Essential?,It is not. How we switch doesnt matter, whether co-operative, with stack fiddling, or using the Stackless transform. It all works.,What is a coroutine?,Coroutines can switch“ to eac

8、h other There is always one current“ coroutine monitored in a Group structures current Currents state is on the machine stack Others are stored as a structure By switching, we replace current“ by a different coroutine and update its group. Well see how this scales,Class Hierarchy,Coroutine,AppCorout

9、ine,AppGreenlet (*),AppTasklet (*),Interpreter-level only,Exposed as distinctcoroutinegreenlettasklet others as needed,(!) Inheritance just for implementation brevity, not exposed to the user,(*) right now done in app-level,Simple API,c = coroutine() c.bind(func, args) c.switch()c.alive c.kill() cor

10、outine.getcurrent()Enough to build everything else on top,Who Am I Problem,How do we define where a coroutine starts and ends? What is current? What is running right now? Am I a coroutine, a tasklet, a greenlet, something else?,Remarks On Generators,They are only one frame level deep Special case of

11、 coroutine with implicit return target Who am I is simple because it is exactly determined by entering/leaving the single frame,Remarks on Tasklets,Well isolated by design Channels are an abstraction that frees the user from the need to know a jump target rendevouz point. The addition of transferrin

12、g data is just for convenience Not much more than coroutines plus the automatic jump management,Essential Evolution,Tasklets and generators are special who am I solutions I actually choosed tasklets to avoid the problem Greenlets dealt a bit with it The parent property to organize greenlets Coroutin

13、es are more basic and needed an explicit concept for maintaining current This led to a general solution!,You Are What You Switch To,current is never stored. There is no switching between concepts. Only similar things can be seen. The running program is whatever you like. You determine what it was by

14、 the jump to something else. The power lies in doing nothing at all Just keep track where the history of a jump must be stored,How can things co-exist?,Every coro-class has its own Group singleton instance Coro-classes are created with an active instance representing the whole program A coro-class c

15、urrent is by definition active until we update this coro-class Group instance Coroutines dont see greenlets dont see tasklets dont see what has a different Group instance.,Finale: Composability,By views, we can run different concepts at the same time, and there is no overhead added We can run differ

16、ent sets of tasklets, grouped by giving them different groups We can mix this all, since groups cannot interfere by construction Confused? Maybe a picture helps.,Per group view of the world,Note that there is no implied relationship to the actually called functions at all. It is all about switching inside of groups,Things To Do for C,C-Stackless has tasklets, only. Provide coroutines as the basic switching concept. Let tasklets inherit from that. Implement Groups to allow for multiple concepts,

展开阅读全文
相关资源
相关搜索

当前位置:首页 > 行业资料 > 其它行业文档

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号