Serhiy Storchaka <storchaka+cpyt...@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 <rep...@bugs.python.org>
<https://bugs.python.org/issue32234>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to