[Python-ideas] Monitor implementation for the stdlib?

Christopher D. Leary christopher.leary at cornell.edu
Mon Oct 22 01:29:40 CEST 2007


I was surprised to find that there is no "monitor construct"
implementation for the stdlib. I wrote one that I feel is pretty
Pythonic, and I'd like it to be torn apart :)

It's fairly well documented -- for most standard monitor use cases you
can simply inherit the Monitor class and use the Monitor-specific
condition variables. Hopefully the accompanying examples will also help
to clarify the usage. They're somewhat silly, but get the idea across.

As an aside, because this seems to come up in every conversation I've
had about monitors in python: if I'm not mistaken, monitors are useful
with or without the GIL :)

Monitors are nifty tools that make complex synchronization problems
somewhat simpler (though more serialized). So far as I understand it,
the GIL provides single-bytecode atomicity, and monitor methods are
rarely single instructions. Plus, Jython and IronPython don't have a
GIL, so I would argue that monitors can still be valuable to "Python the
language" even if you won't allow that they can be valuable to "Python
the standard implementation".

Looking forward to hearing everybody's opinions.

Cheers,

Chris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: monitor.py
Type: text/x-python
Size: 8421 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20071021/34eb222e/attachment.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bridge.py
Type: text/x-python
Size: 3328 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20071021/34eb222e/attachment-0001.py>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: bar.py
Type: text/x-python
Size: 4448 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20071021/34eb222e/attachment-0002.py>


More information about the Python-ideas mailing list