Monday, 22 March 2021

Understand the implementation of event loops in Python asyncio

I'm watching import asyncio: Learn Python's AsyncIO #2 - The Event Loop to try to understand the inner working of event loops. In the video, the instructor tried to explain this on the operating system level. However, I know very few about operating systems and have a very hard time understanding his explanation.

Questions

At 9:46, the instructor showed a system calls manual about the select method.

  1. The instructor said that the select method allows us to provide a list of file descriptors. What is a file descriptor?
  2. What does the select method do? What would happen to the provided file descriptors after calling select on them?
  3. The manual said that the select method is 'synchronous I/O multiplexing'. What is multiplexing? In what way is the select method 'synchronous I/O multiplexing'?
  4. How does the Python implementation of event loops make use of the select method?

At 11:11, the instructor showed a Windows Dev Center manual about 'I/O Completion Ports'.

  1. The instructor said that "if there are more events than available threads, some events will wait until one of threads in the pool frees up." So basically it works similarly to concurrent.futures.ThreadPoolExecutor?
  2. How does the Python implementation of event loops make use of 'I/O Completion Ports'?

At 22:31, the instructor showed the source code of _run_once method in base_events.py.

  1. The second step of _run_once method is polling for I/O. Does it polls for I/O by using the _select.select method at line 1854 (24:41)?

At 25:30, the instructor showed the source code of _process_events method in selector_events.py.

  1. What do the mask, selectors, reader, writer variables in the code refer to? What do they do?

Finally,

  1. What kinds of general computer science knowledge do I need to know in order to understand event loops?


from Understand the implementation of event loops in Python asyncio

No comments:

Post a Comment