multithreading - How can I do asynchronous programming but hide it in Python? -


am getting head round twisted, threading, stackless, etc. etc. , appreciate high level advice.

suppose have remote clients 1 , 2, connected via websocket running in page on browsers. here ideal goal:

for cl in (1,2):     guess[cl] = show(cl, choice("pick number:", range(1,11))) checkpoint() if guess[1] == guess[2]:     show((1,2), display("you picked same number!")) 

ignoring mechanics of show, choice , display, point want show call asynchronous. each client gets shown choice. code waits @ checkpoint() threads (or whatever) rejoin.

i interested in hearing answers if involve hairy things rewriting source code. i'd interested in less hairy answers involve compromising bit on syntax.

in python, widely-used approach async/event-based network programming hides model programmer gevent.

beware: kind of trickery works making tasks yield control implicitly, encourages same sorts of surprising bugs tend appear when os threads involved. local reasoning such problems harder explicit yielding, , convenience of avoiding callbacks might not worth trouble introduced inherent pitfalls. perhaps important library author yourself: approach not pure python, , force dependencies , interpreter restrictions on users of library.

a lot of discussion topic sprouted (especially between gevent , twisted camps) while guido working on asyncio library, called tulip @ time. summarized main issues here.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -