multiprocessing.sharedctypes and built-in locks

Aaron Brady castironpi at gmail.com
Mon Mar 16 04:19:14 EDT 2009


On Mar 15, 11:42 pm, Ahmad Syukri b <syoc... at gmail.com> wrote:
> On Mar 15, 6:19 am, Aaron Brady <castiro... at gmail.com> wrote:
>
>
>
> > Your code hung on my machine.  The call to 'main()' should be in an
> > 'if __name__' block:
>
> > if __name__== '__main__':
> >     main()
>
> > Is it possible you are just seeing the effects of the non-atomic
> > '__iadd__' operation?  That is, the value is read, added, and written
> > at different times, between which other processes might have
> > intervened.
>
> I've forgotten to remove ' gl.append(mp.Lock()) ' from the second
> code.
>
> Anyways if what you said is true, then why doesn't the documentation
> say so?

I couldn't find it either.  It's not one of the guarantees that Python
makes.  Operations aren't atomic by default, such as unless stated
otherwise.  Though it does seem counterintuitive to have to write:

with a_lock:
    a+= 1

> I also realized that the created lock's release and acquire
> methods are also imbued to the created shared object, and this is also
> undocumented.

Sorry, I don't follow you.  By the way, your first example didn't
produce the expected result on my machine-- even with the 'if
__name__' statement.



More information about the Python-list mailing list