[issue32234] Add context management to mailbox.Mailbox
Serhiy Storchaka
report at bugs.python.org
Wed Dec 6 11:48:07 EST 2017
Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:
There is an ambiguity. What should the context manager do? Should it call a close() on exit (as the OP implies)? Or call lock() on enter and unlock() on exit as in Barry's example? Both behaviors look reasonable.
"In the face of ambiguity, refuse the temptation to guess" and "Explicit is better than implicit". This is perhaps the reason why this feature is not implemented yet. Perhaps there were discussions about this in the past.
contextlib.closing() can be used for explicit requesting the first behavior. Maybe it's a time to add contextlib.locked() or something like.
----------
nosy: +ncoghlan, r.david.murray, serhiy.storchaka, yselivanov
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue32234>
_______________________________________
More information about the Python-bugs-list
mailing list