Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
有谁知道我是否可以安全地从另一个线程调用 epoll.register ?
这是我的想象:
http://docs.python.org/library/select.html
在您更改问题后,我更改了答案。
这不是“线程安全的”,因为每个线程都会影响同一个 epoll 对象。向 epoll 对象注册一个新的 fd 仍然会对该对象进行。
该特定对象没有理由在不同的线程之间具有不同的状态,因为在这种情况下,应该为每个线程创建一个对象。
所以,简短的回答:您的设置将起作用。
事实上,python stdlib http.server 包使用相同的方法(只是使用 poll 而不是 epoll)。它在一个线程中创建一个轮询对象,并使用一个单独的线程对其进行轮询。