开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (2)
master
review
master
分支 (2)
master
review
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (2)
master
review
microPython
/
docs
/
library
/
uasyncio.rst
microPython
/
docs
/
library
/
uasyncio.rst
uasyncio.rst 7.91 KB
一键复制 编辑 原始数据 按行查看 历史
chenchi 提交于 2021年06月03日 16:44 +08:00 . first commit

:mod:`uasyncio` --- asynchronous I/O scheduler

.. module:: uasyncio
 :synopsis: asynchronous I/O scheduler for writing concurrent code

|see_cpython_module| Core functions

.. function:: create_task(coro)

 Create a new task from the given coroutine and schedule it to run.

 Returns the corresponding `Task` object.

.. function:: run(coro)

 Create a new task from the given coroutine and run it until it completes.

 Returns the value returned by *coro*.

.. function:: sleep(t)

 Sleep for *t* seconds (can be a float).

 This is a coroutine.

.. function:: sleep_ms(t)

 Sleep for *t* milliseconds.

 This is a coroutine, and a MicroPython extension.

Additional functions

.. function:: wait_for(awaitable, timeout)

 Wait for the *awaitable* to complete, but cancel it if it takes longer
 that *timeout* seconds. If *awaitable* is not a task then a task will be
 created from it.

 If a timeout occurs, it cancels the task and raises ``asyncio.TimeoutError``:
 this should be trapped by the caller.

 Returns the return value of *awaitable*.

 This is a coroutine.

.. function:: wait_for_ms(awaitable, timeout)

 Similar to `wait_for` but *timeout* is an integer in milliseconds.

 This is a coroutine, and a MicroPython extension.

.. function:: gather(*awaitables, return_exceptions=False)

 Run all *awaitables* concurrently. Any *awaitables* that are not tasks are
 promoted to tasks.

 Returns a list of return values of all *awaitables*.

 This is a coroutine.

class Task

This object wraps a coroutine into a running task. Tasks can be waited on using await task, which will wait for the task to complete and return the return value of the task.

Tasks should not be created directly, rather use create_task to create them.

.. method:: Task.cancel()

 Cancel the task by injecting a ``CancelledError`` into it. The task may
 or may not ignore this exception.

class Event

Create a new event which can be used to synchronise tasks. Events start in the cleared state.

.. method:: Event.is_set()

 Returns ``True`` if the event is set, ``False`` otherwise.

.. method:: Event.set()

 Set the event. Any tasks waiting on the event will be scheduled to run.

.. method:: Event.clear()

 Clear the event.

.. method:: Event.wait()

 Wait for the event to be set. If the event is already set then it returns
 immediately.

 This is a coroutine.

class Lock

Create a new lock which can be used to coordinate tasks. Locks start in the unlocked state.

In addition to the methods below, locks can be used in an async with statement.

.. method:: Lock.locked()

 Returns ``True`` if the lock is locked, otherwise ``False``.

.. method:: Lock.acquire()

 Wait for the lock to be in the unlocked state and then lock it in an atomic
 way. Only one task can acquire the lock at any one time.

 This is a coroutine.

.. method:: Lock.release()

 Release the lock. If any tasks are waiting on the lock then the next one in the
 queue is scheduled to run and the lock remains locked. Otherwise, no tasks are
 waiting an the lock becomes unlocked.

TCP stream connections

.. function:: open_connection(host, port)

 Open a TCP connection to the given *host* and *port*. The *host* address will be
 resolved using `socket.getaddrinfo`, which is currently a blocking call.

 Returns a pair of streams: a reader and a writer stream.
 Will raise a socket-specific ``OSError`` if the host could not be resolved or if
 the connection could not be made.

 This is a coroutine.

.. function:: start_server(callback, host, port, backlog=5)

 Start a TCP server on the given *host* and *port*. The *callback* will be
 called with incoming, accepted connections, and be passed 2 arguments: reader
 and writer streams for the connection.

 Returns a `Server` object.

 This is a coroutine.

This represents a TCP stream connection. To minimise code this class implements both a reader and a writer, and both StreamReader and StreamWriter alias to this class.

.. method:: Stream.get_extra_info(v)

 Get extra information about the stream, given by *v*. The valid values for *v* are:
 ``peername``.

.. method:: Stream.close()

 Close the stream.

.. method:: Stream.wait_closed()

 Wait for the stream to close.

 This is a coroutine.

.. method:: Stream.read(n)

 Read up to *n* bytes and return them.

 This is a coroutine.

.. method:: Stream.readline()

 Read a line and return it.

 This is a coroutine.

.. method:: Stream.write(buf)

 Accumulated *buf* to the output buffer. The data is only flushed when
 `Stream.drain` is called. It is recommended to call `Stream.drain` immediately
 after calling this function.

.. method:: Stream.drain()

 Drain (write) all buffered output data out to the stream.

 This is a coroutine.

This represents the server class returned from start_server. It can be used in an async with statement to close the server upon exit.

.. method:: Server.close()

 Close the server.

.. method:: Server.wait_closed()

 Wait for the server to close.

 This is a coroutine.

Event Loop

.. function:: get_event_loop()

 Return the event loop used to schedule and run tasks. See `Loop`.

.. function:: new_event_loop()

 Reset the event loop and return it.

 Note: since MicroPython only has a single event loop this function just
 resets the loop's state, it does not create a new one.

This represents the object which schedules and runs tasks. It cannot be created, use get_event_loop instead.

.. method:: Loop.create_task(coro)

 Create a task from the given *coro* and return the new `Task` object.

.. method:: Loop.run_forever()

 Run the event loop until `stop()` is called.

.. method:: Loop.run_until_complete(awaitable)

 Run the given *awaitable* until it completes. If *awaitable* is not a task
 then it will be promoted to one.

.. method:: Loop.stop()

 Stop the event loop.

.. method:: Loop.close()

 Close the event loop.

.. method:: Loop.set_exception_handler(handler)

 Set the exception handler to call when a Task raises an exception that is not
 caught. The *handler* should accept two arguments: ``(loop, context)``.

.. method:: Loop.get_exception_handler()

 Get the current exception handler. Returns the handler, or ``None`` if no
 custom handler is set.

.. method:: Loop.default_exception_handler(context)

 The default exception handler that is called.

.. method:: Loop.call_exception_handler(context)

 Call the current exception handler. The argument *context* is passed through and
 is a dictionary containing keys: ``'message'``, ``'exception'``, ``'future'``.
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

HeliosSDK microPython组件
暂无标签
MIT
使用 MIT 开源许可协议
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quecpython/microPython.git
git@gitee.com:quecpython/microPython.git
quecpython
microPython
microPython
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /