New submission from Martin Richard: An exception can be raised in SubprocessTransport.__init__() from SubprocessTransport._start() - for instance because an exception is raised in the preexec_fn callback.
In this case, the calling function never gets a reference to the transport object, and cannot close the transport. Hence, when the object is deleted, an "unclosed transport" ResourceWarning is always triggered. Here is a test case showing this behavior: import asyncio loop = asyncio.get_event_loop() try: loop.run_until_complete(asyncio.create_subprocess_exec('/doesntexist')) except FileNotFoundError: pass finally: loop.close() I propose the attached patch as a solution, which call SubprocessTransport.close() when an exception is raised in SubprocessTransport._start() in the constructor. ---------- components: asyncio files: transport_close_when_exception_init.patch keywords: patch messages: 247746 nosy: gvanrossum, haypo, martius, yselivanov priority: normal severity: normal status: open title: asyncio.BaseSubprocessTransport triggers an unavoidable ResourceWarning if process doesn't start type: resource usage versions: Python 3.4, Python 3.5 Added file: http://bugs.python.org/file40082/transport_close_when_exception_init.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue24763> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com