微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在程序退出的消息中忽略exception

我最初想在Windows上进行asynchronousstream通信。

from asyncio import * from asyncio.subprocess import PIPE,STDOUT,DEVNULL import sys async def test(exe): inst = await create_subprocess_exec(exe,stdin=PIPE,stdout=PIPE,stderr=STDOUT) inst.stdin.close() inst.wait() # for subprocess' pipes on Windows def initialize_async(): if sys.platform == 'win32': set_event_loop(ProactorEventLoop()) return get_event_loop() loop = initialize_async() loop.run_until_complete(test('attrib.exe')) loop.close()

上面的代码生成以下内容

Exception ignored in: <bound method BaseSubprocesstransport.__del__ of <_WindowsSubprocesstransport closed pid=65088 running stdin=<_ProactorWritePipeTransport closed> stdout=<_ProactorReadPipeTransport closing fd=476 read=<_OverlappedFuture cancelled>>>> Traceback (most recent call last): File "C:Program Filespython36libasynciobase_subprocess.py",line 132,in __del__ self.close() File "C:Program Filespython36libasynciobase_subprocess.py",line 106,in close proto.pipe.close() File "C:Program Filespython36libasyncioproactor_events.py",line 84,in close self._loop.call_soon(self._call_connection_lost,None) File "C:Program Filespython36libasynciobase_events.py",line 573,in call_soon self._check_closed() File "C:Program Filespython36libasynciobase_events.py",line 357,in _check_closed raise RuntimeError('Event loop is closed') RuntimeError: Event loop is closed Exception ignored in: <object repr() Failed> Traceback (most recent call last): File "C:Program Filespython36libasyncioproactor_events.py",line 95,in __del__ warnings.warn("unclosed transport %r" % self,ResourceWarning,File "C:Program Filespython36libasyncioproactor_events.py",line 54,in __repr__ info.append('fd=%s' % self._sock.fileno()) File "C:Program Filespython36libasynciowindows_utils.py",line 152,in fileno raise ValueError("I/O operatioon on closed pipe") ValueError: I/O operatioon on closed pipe

我怎样才能删除这个错误? stdin.close和等待似乎是不够的。

c#winforms:确定程序的第一次运行

在Windows的后台运行PHP“exec()”?

如何以编程方式检测“安装更新并closures计算机”屏蔽图标是否出现在开始/“closures”button的顶部?

c#winform屏幕分辨率

Python套接字在LAN上工作,但不在Wifi上工作

如何使用C#访问iOS应用程序的Documents文件

是否有可能在Windows上捕获另一个进程的未处理的exception?

间谍+和窗户closures时,他们失去了重点

DynamoDB Local Basic PHP安装程序

python加载Windows deault loader

请注意,与同步编程不同,许多asyncio函数实际上是应该等待的coroutines 。 看看如何在文档中定义wait() :

你应该修复你的代码来等待这个协程:

async def test(exe): inst = await create_subprocess_exec(exe,stderr=STDOUT) data = await inst.stdout.readline() # readline,for example,is also coroutine. print(data) await inst.wait()

你现在不会看到任何错误

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐