Andrew Svetlov added the comment:

Yes, the approach use hackery shadows for binding global variables on shutdown 
stage.
The same I've found in subprocess module: see 
https://github.com/python/cpython/blob/master/Lib/subprocess.py#L1544

The problem is: I want to inform users about unclosed resources.
Printouts like
`TypeError: 'NoneType' object is not callable`
or 
`AttributeError: 'NoneType' object has no attribute 'warn'` are too confusing 
for casual developer.

On shutdown logger and warnings modules may be destroyed at the moment of 
__del__ call, so `warnings.warn`, `loop.call_exception_handler` etc. are 
forbidden.

As an option we can add atexit handler to store shutdown flag into loop object 
(I don't know other way to get info is interpreter in shutdown or not).

According to the flag we can eihter print some short text about non-closed 
resources or raise proper ResourceWarning along with comprehensive logging with 
stacktrace if PYTHONASYNCIO is on.

Maybe I've missed something and you can suggest better solution.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue25074>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to