[Python-Dev] Pythonic concurrency - cooperative MT (original) (raw)
Gustavo J. A. M. Carneiro gjc at inescporto.pt
Fri Sep 30 23:55:44 CEST 2005
- Previous message: [Python-Dev] Pythonic concurrency - cooperative MT
- Next message: [Python-Dev] Pythonic concurrency - cooperative MT
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Fri, 2005-09-30 at 18:33 +0200, Antoine Pitrou wrote:
Hi Jp,
Le vendredi 30 septembre 2005 à 12:20 -0400, Jp Calderone a écrit : > "Advocating" might be putting it too strongly :) "Experimenting with" > describes the current state of things most accurately. Ok :) > The problem it aims to solve is integration with cooperative threading > systems which don't work very well. An example of such a loop is the > wx event loop. > > Whenever a modal dialog is displayed or a menu is activated, wx's loop > stops cooerating.
That is wx's problem. Try PyGTK some day; I hear it's really good! ;-)
This specific problem hides the more general problem, which is that GUI and network activities have different typical latencies. As I explained on the twisted ML, a GUI needs very good response times to feel friendly (typically below 20 or even 10 ms.), whereas some network protocols have non-trivial calculations which can go above 100 ms.
With PyGTK a typical solution for this is to use a generator function executing an "idle function", which would make the non-trivial calculations, but yield control back to the main loop periodically, in order to process GUI events. For example, see the last code block in http://www.async.com.br/faq/pygtk/index.py?req=show&file=faq23.020.htp
Moreover, you don't want a sudden flood of network events to block events in the GUI.
Process one event at a time, after each event give back control to the main loop, and give low priority to socket IO events. Problem solved.
This is why even without considering wx's specificities, it is still useful to keep GUI and network activities in separate threads.
You are considering a scenario that seldom happens to design a solution that is far too complicated for most cases.
Regards.
-- Gustavo J. A. M. Carneiro <gjc at inescporto.pt> <gustavo at users.sourceforge.net> The universe is always one step beyond logic
- Previous message: [Python-Dev] Pythonic concurrency - cooperative MT
- Next message: [Python-Dev] Pythonic concurrency - cooperative MT
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]