yield, curry, mix-in, new.function, global, closure, .... what will work?

ecir.hana at gmail.com ecir.hana at gmail.com
Mon Apr 16 09:28:19 EDT 2007


On Apr 16, 3:05 am, Paul Rubin <http://phr...@NOSPAM.invalid> wrote:
> ecir.h... at gmail.com writes:
>
> > 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.

Thanks for the reply! And at the same time, please bear with me.

If I understand correctly: when one thread acquires the lock, every
other thread has to wait. If so, this is not exacly what I would like
to have since the thread might take a bit longer to finish.

The reason why I try so hard to use local variables is that they are
inherently thread-safe. So I don't even mind to copy changer() every
time run() is called - run() has it's own local variables i, j, no one
has to touch them except it's ("local") function changer(). But the
problem is, I don't know how to propagate run()'s variables into
changer() without declarating them as changer()'s arguments (it would
be ok to append the declaration during run-time, though, if I only
knew how).




More information about the Python-list mailing list