- It monitors sockets, open files, and pipes (anything with a fileno() method that returns a valid file descriptor) until they become readable or writable, or a communication error occurs.
- when file object which registered to selector is ready to read / write, it will be put to a event queue.
- when applying to normal file open, it does not mean key.data will be triggered each time the file is modified.
- each event in the event loop will also know the callback funtion it needs to execute next.
- If we call select(None), the call will block until a monitored file object becomes ready.
- using single thread callback / coroutine async method, we don’t need to synchronize a shared data structure (like a list), because any given time, the list is access by no more than 1 thread.
- dis -> disassembly of python bytecode
- A Python generator encapsulates a stack frame plus a reference to some code, the body of gen_fn
- The frame has a “last instruction” pointer, the instruction it executed most recently. In the beginning, the last instruction pointer is -1, meaning the generator has not begun
- The advantage of using coroutine based async is that coroutine can be paused and resumed, so we can write the code to be run next just after yield from,
it will be paused and give out control and then wait for the control back to continue to run the code below. So when programming, it’s just like writing sync code.
- yield from / await only provides a async framework / capability. The trigger / ready_event after the thing is done actually needs low-level package / features to support such as selector.
- Future is a result that a coroutine is waiting for.
- Why selector is called I/O Multiplexing (多路复用)
- what does ready mean in this context? for a socket / file / pipeline ?
- what kind of object will have fileno, is there any pattern or rule to follow?
- is it the thing so called EventLoop?
events = sel.select()
for key, mask in events:
callback = key.data