What File Descriptor object does Python AsyncIO's loop.add_reader() expect?

后端 未结 2 569
攒了一身酷
攒了一身酷 2021-01-02 18:19

I\'m trying to understand how to use the new AsyncIO functionality in Python 3.4 and I\'m struggling with how to use the event_loop.add_reader(). From the limited discussion

2条回答
  •  温柔的废话
    2021-01-02 19:18

    you cannot use add_reader on local files, because:

    • It cannot be done using select/poll/epoll
    • It depends on the operating system
    • It cannot be fully asynchronous because of os limitations (linux does not support async fs metadata read/write)

    But, technically, yes you should be able to do async filesystem read/write, (almost) all systems have DMA mechanism for doing i/o "in the background". And no, local i/o is not really fast such that no one would want it, the CPU are in the order of millions times faster that disk i/o.

    Look for aiofile or aiofiles if you want to try async i/o

提交回复
热议问题