已解决 RuntimeError: There is no current event loop in thread ‘Thread-1‘.

简介: Jetson Xavier NX 报错 RuntimeError: There is no current event loop in thread 'Thread-1'.异常错误,已解决

Jetson Xavier NX报错异常RuntimeError: There is no current event loop in thread 'Thread-1'. 已解决


一、问题描述
这个错误是我在Jetson Xavier NX使用多线程的时候遇到的,这个异常是在线程 'Thread-1' 中没有当前的事件循环引起的。意思是使用 asyncio 库的时候,它就需要在主线程中创建一个事件循环并在这个事件循环上运行异步任务。

二、解决方法
解决方法其实很简单,只需要在主线程中创建和设置事件循环就行。


import asyncio
asyncio.set_event_loop(asyncio.new_event_loop())
AI 代码解读
    把上面的代码放到主线程里的最开始处。

    为啥将它限制在主线程的最开始处,主要原因就是避免在其他线程中运行涉及到 asyncio 的代码。将涉及到 asyncio 的代码移动到主线程里面,这样是确保有一个可用的事件循环。也意味你的异步任务会被限制在主线程里面去执行,而不是在其他线程里面执行。
AI 代码解读

image.png
image.png

目录
打赏
0
0
0
0
9
分享
相关文章
may have been in progress in another thread when fork() was called.
may have been in progress in another thread when fork() was called.
153 0
may have been in progress in another thread when fork() was called.
Thread State 详解
前言 文本已收录至我的GitHub仓库,欢迎Star:github.com/bin39232820… 种一棵树最好的时间是十年前,其次是现在
184 0
Can't create handler inside thread that has not called Looper.prepare()
版权声明:本文为博主原创文章,转载请标明出处。 https://blog.csdn.net/chaoyu168/article/details/52163029 最近做项目时出现个问题。
1214 0
lvm[12446]: Another thread is handling an event. Waiting
在检查一Linux服务器时,发现日志里面有大量“lvm[12446]: Another thread is handling an event. Waiting...” Jul  4 00:01:42 localhost lvm[12446]: Another thread is handling an event.
1044 0
|
9月前
|
【ERROR】asyncio.run(main())报错:RuntimeError: Event loop is closed
【ERROR】asyncio.run(main())报错:RuntimeError: Event loop is closed
278 0
Thread.sleep(0) vs Thread.sleep(1) vs Thread.yield() vs Object.wait()
Thread.sleep(0) vs Thread.sleep(1) vs Thread.yield() vs Object.wait()
|
10月前
|
关于thread使用的错误:pure virtual method called terminate called without an active exception
关于thread使用的错误:pure virtual method called terminate called without an active exception
210 1
wait for stopper event to be increased
环境OS:SunOS hostname 5.10 Generic_127111-11 sun4u sparc SUNW,Sun-Fire-V490DB: Oracle Database 10g Enterprise Edition Release 10.
1089 0
Thread.sleep() 和 Thread.yield() 区别
Thread.sleep() 和 Thread.yield() 区别 thread Thread.yield() api中解释: 暂停当前正在执行的线程对象,并执行其他线程。
1294 0

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等