我试过这个:
import trio
from gevent import monkey, spawn
monkey.patch_all()
async def async_double(x):
return 2 * x
def run():
return trio.run(async_double, 3)
g = spawn(run)
g.join()
但是我收到错误:
Traceback (most recent call last):
File "src/gevent/greenlet.py", line 908, in gevent._gevent_cgreenlet.Greenlet.run
File "/Users/xxx/t.py", line 10, in run
return trio.run(async_double, 3)
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/trio/_core/_run.py", line 1990, in run
runner = setup_runner(
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/trio/_core/_run.py", line 1885, in setup_runner
io_manager = TheIOManager()
File "<attrs generated init trio._core._io_kqueue.KqueueIOManager>", line 15, in __init__
self.__attrs_post_init__()
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/trio/_core/_io_kqueue.py", line 33, in __attrs_post_init__
force_wakeup_event = select.kevent(
AttributeError: module 'select' has no attribute 'kevent'
2023-07-28T21:06:31Z <Greenlet at 0x105d22370: run> failed with AttributeError
我也尝试先导入和修补 gevent,但在运行之前就失败了:
from gevent import monkey, spawn
monkey.patch_all()
import trio
追溯:
File "/Users/xxx/t.py", line 3, in <module>
import trio
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/trio/__init__.py", line 18, in <module>
from ._core import (
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/trio/_core/__init__.py", line 27, in <module>
from ._run import (
File "/Users/xxx/Library/Python/3.9/lib/python/site-packages/trio/_core/_run.py", line 2458, in <module>
raise NotImplementedError("unsupported platform")
NotImplementedError: unsupported platform
我想我有时设法让第一种方法(首先导入三重奏)工作(但代码有点不同并且更复杂),但我想知道这是否只是幸运并且稍后会出现问题。
这是在 MacOS 上,但需要跨平台。