multithreading
Christopher Saunter
Christopher.Saunter at durham.ac.uk
Mon May 20 07:08:24 EDT 2002
Nils Kassube (nika at kassube.de) wrote:
: "Rob Hall" <bloke at ii dot net> writes:
: > Can anyone point me to a useful tutorial on multithreading?
: One advice: Avoid multithreading like the plague.
: Multithreading is a very big stability risk if you don't know exactly
: what you are doing, i.e. most programmers most of the time.
I have found multithreaded programing under Python to be rock solid, if a
few simple rules are followed. Well, three infact.
1. Prefereably pass information to threads when they are created, not at
run time.
2. All run time comms between threads is via a dictionary, with two
functions that use semaphore protection to set/read variables to /
from the dictionary. Maybe not so good where you need a lot of comms
between threads?
3. Using wxPython, wxMutexGuiEnter() and wxMutexGuiLeave() are sufficient
and necessary for gui work from non main threads. I imagine most GUI
libraries have a similar concept.
Following these three rules, I have a program that can hapilly run 5
threads, all accessing the GUI, and with the addition of a few carefully
placed time.sleep(x) calls remains highly responsive.
---
cds
More information about the Python-list
mailing list