为什么MicroPython中的uasyncio模块没有任何“run”函数?

huangapple go评论85阅读模式
英文:

Why does uasyncio module in micropython doesn't have any "run" function?

问题

I am using an ESP8266 board with micropython.

I tried to use asyncio, but it doesn't work and says me that:

Traceback (most recent call last):
  File "<stdin>", line 10, in <module>
  File "<stdin>", line 7, in main
AttributeError: 'module' object has no attribute 'run'

I took a look about what does uasyncio contains and I got this:

>>> import uasyncio as asyncio
>>> asyncio.
__class__       __name__        __path__        DEBUG
log             select          sleep           sleep_ms
time            ucollections    uerrno          utimeq
type_gen        set_debug       CancelledError  TimeoutError
EventLoop       SysCall         SysCall1        StopLoop
IORead          IOWrite         IOReadDone      IOWriteDone
get_event_loop  SleepMs         cancel          TimeoutObj
wait_for_ms     wait_for        coroutine       ensure_future
Task            _socket         PollEventLoop   StreamReader
StreamWriter    open_connection                 start_server
uasyncio        core

After some researches, I have found in this documentation that uasyncio is supposed to get functions like new_event_loop(), run, etc... that I absolutely don't have there...

There is my script:

from robot import *
import uasyncio as asyncio

def main(args):
    robot = MicroportalRobot("robotName", "serverAddr", 8266)
    asyncio.run(robot.main())

if __name__ == "__main__":
    main([])

Why?

英文:

I am using an ESP8266 board with micropython.

I tried to use asyncio, but it doesn't work and says me that :

Traceback (most recent call last):
  File &quot;&lt;stdin&gt;&quot;, line 10, in &lt;module&gt;
  File &quot;&lt;stdin&gt;&quot;, line 7, in main
AttributeError: &#39;module&#39; object has no attribute &#39;run&#39;

I took a look about what does uasyncio contains and I got this :

&gt;&gt;&gt; import uasyncio as asyncio
&gt;&gt;&gt; asyncio.
__class__       __name__        __path__        DEBUG
log             select          sleep           sleep_ms
time            ucollections    uerrno          utimeq
type_gen        set_debug       CancelledError  TimeoutError
EventLoop       SysCall         SysCall1        StopLoop
IORead          IOWrite         IOReadDone      IOWriteDone
get_event_loop  SleepMs         cancel          TimeoutObj
wait_for_ms     wait_for        coroutine       ensure_future
Task            _socket         PollEventLoop   StreamReader
StreamWriter    open_connection                 start_server
uasyncio        core

After some researches, I have found in this documentation that uasyncio is supposed to get functions like new_event_loop(), run, etc... that I absolutely don't have there...

There is my script :

from robot import *
import uasyncio as asyncio

def main(args):
    robot = MicroportalRobot(&quot;robotName&quot;, &quot;serverAddr&quot;, 8266)
    asyncio.run(robot.main())

if __name__ == &quot;__main__&quot;:
    main([])

Why?

答案1

得分: 1

你正在寻找的功能是uasyncio v3的一部分,作为micropython 1.13的一部分发布。您需要至少与1.13版本相同或更新的micropython版本才能使用它们。您的评论表明您使用的是micropython 1.11,这意味着您使用的是旧版本的v2 uasyncio实现,不具备这些功能。

您需要安装更新的micropython版本,或者继续使用uasyncio v2 API。

英文:

The features you're looking for are part of uasyncio v3, released as part of micropython 1.13. You need a micropython version at least as recent as 1.13 to use them. Your comments indicate you're on micropython 1.11, meaning you have the old v2 uasyncio implementation, which does not have these features.

You will need to install a more recent micropython build, or stick to the uasyncio v2 API.

huangapple
  • 本文由 发表于 2023年8月4日 03:19:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/76831046.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定