yield, curry, mix-in, new.function, global, closure, .... what will work?
Paul Rubin
http
Sun Apr 15 21:05:17 EDT 2007
ecir.hana at gmail.com writes:
> On Apr 15, 8:07 pm, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> > That is total madness. Just use a normal object or dictionary with a lock.
>
> Please, can you elaborate further, I'm not sure if I understood.
> Should I lock global variables i, j during the execution of run()? In
> that case I have to apologize, I showed rather simplified version of
> the actual problem I have - in fact changer() and run() will be a bit
> more complex thus executing a bit longer and perhaps causing a dead-lock.
Put both variables into one shared object with a lock (see the docs for
threading.RLock()). Acquire the lock before modifying or reading the
variables, and release it afterwards. That is the traditional way.
Another way popular in Python is to have separate threads for changer
and run, and have them communicate through Queue.Queue objects. In no
case should you attempt to write a function that messes with another
function's local variables. Local variables are called "local" for a
reason ;-).
Basically this stuff takes more understanding and getting used to than
I can really convey in a newsgroup post. You might look at some
Wikipedia articles or ASPN recipes about concurrent programming, or
get the Python Cookbook.
More information about the Python-list
mailing list