usocket.select
时间: 2024-01-13 08:03:07 浏览: 26
usocket.select is a method provided by the MicroPython usocket module which allows a MicroPython program to monitor multiple sockets for input or output readiness. It takes three arguments: read list, write list, and error list. Each of these lists contains sockets that the program wants to monitor for a particular event. The method blocks until one or more of the sockets are ready for the desired event, at which point it returns a tuple containing three lists: sockets that are ready for reading, sockets that are ready for writing, and sockets that have an error.
Example usage:
```python
import usocket
# create two sockets
sock1 = usocket.socket()
sock2 = usocket.socket()
# connect sock1 to a server
sock1.connect(('example.com', 80))
# add the sockets to the read and write lists
read_list = [sock1, sock2]
write_list = [sock2]
# monitor the sockets for input/output readiness
ready_to_read, ready_to_write, in_error = usocket.select(read_list, write_list, [])
# process the sockets that are ready for reading or writing
for s in ready_to_read:
# read data from s
pass
for s in ready_to_write:
# write data to s
pass
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)