[Python-ideas] Concurrent safety?

Bruce Leban bruce at leapyear.org
Mon Oct 31 23:58:47 CET 2011


On Sun, Oct 30, 2011 at 8:11 PM, Mike Meyer <mwm at mired.org> wrote:

> Any attempt to mutate an object that isn't currently locked will raise
> an exception. Possibly ValueError, possibly a new exception class just
> for this purpose. This includes rebinding attributes of objects that
> aren't locked.
>

Do you mean that at any time attempting to mutate an unlocked object throws
an exception? That would mean that all of my current code is broken. Do you
mean, that inside the control of 'locking', you can't mutate an unlocked
object? That still breaks lots of code that is safe. You can't use
itertools.cycle anymore until that's updated in a completely unnecessary
way:

def cycle(iterable):
    # cycle('ABCD') --> A B C D A B C D A B C D ...
    saved = []
    for element in iterable:
        yield element
        saved.append(element)  *# throws an exception when called on a
locked iterable*
    while saved:
        for element in saved:
              yield element


I think the semantics of this need to be tightened up. Furthermore, merely
*reading* an object that isn't locked can cause problems. This code is not
thread-safe:

    if element in dictionary: return dictionary[element]

so you have to decide how much safety you want and what cost we're willing
to pay for this.

--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20111031/48a2a047/attachment.html>


More information about the Python-ideas mailing list