小编cal*_*vin的帖子

如果你嵌套extern"C"会发生什么?

看起来嵌套extern"C"是合法的.例如:

extern "C" extern "C" void foo();
Run Code Online (Sandbox Code Playgroud)

第二个extern "C"基本上被忽略了.这是由C++标准保证的吗?哪里?

c++ nested extern

9
推荐指数
1
解决办法
549
查看次数

如何使用高级 asyncio API 干净地终止子进程?

这是我尝试使用高级 asyncio 子进程 API过早终止子进程的程序:

import asyncio

async def test():
    process = await asyncio.create_subprocess_shell(
        "sleep 2 && echo done",
        stdout=asyncio.subprocess.PIPE,
    )
    await asyncio.sleep(1)
    process.kill()
    await process.wait()
    # process._transport.close()

asyncio.run(test())
Run Code Online (Sandbox Code Playgroud)

退出时,它将以下内容写入stderr

$ python3.9 test.py

Exception ignored in: <function BaseSubprocessTransport.__del__ at 0x1065f0dc0>
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_subprocess.py", line 126, in __del__
    self.close()
  File "/usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_subprocess.py", line 104, in close
    proto.pipe.close()
  File "/usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/unix_events.py", line 536, in close
    self._close(None)
  File "/usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/unix_events.py", line 560, in _close
    self._loop.call_soon(self._call_connection_lost, exc)
  File "/usr/local/Cellar/python@3.9/3.9.2_1/Frameworks/Python.framework/Versions/3.9/lib/python3.9/asyncio/base_events.py", line 746, …
Run Code Online (Sandbox Code Playgroud)

python subprocess kill python-3.x python-asyncio

5
推荐指数
0
解决办法
778
查看次数

标签 统计

c++ ×1

extern ×1

kill ×1

nested ×1

python ×1

python-3.x ×1

python-asyncio ×1

subprocess ×1