What are those asyncio files in /proc/*/fd

Viewed 115

Running an asyncio.sleep task causes the following files to be present in /proc/*/fd:

lrwx------ 1 mango mango 64 27. Dez 12:40 3 -> 'anon_inode:[eventpoll]'
lrwx------ 1 mango mango 64 27. Dez 12:40 4 -> 'socket:[330143]'
lrwx------ 1 mango mango 64 27. Dez 12:40 5 -> 'socket:[330144]'

What does this stuff do for asyncio?

I had a problem with multiprocessing that was solved by creating a new event loop in the new process, so I assume there is some link between the processes. Either a pipe (which I think is also a file?) or this stuff.

1 Answers

What does this stuff do for asyncio?

Those are resources acquired by the asyncio event loop for its internal workings.

The first file descriptor is likely to be the file descriptor returned by epoll_create(), which is passed to epoll() in order to used to monitor network and other IO in order to resume coroutines suspended while waiting for IO.

The second and third file descriptor are likely to refer to the socket pair created by the event loop in order to "wake up" when a signal is received or when another thread requests execution of a function in the event loop thread. In both cases the wakeup is implemented by writing a byte to the write end of the socket pair, which notifies the event loop's reactor that monitors the read end.

Related