python - Make epoll return an fd once, without writing -


i have master , worker thread. master thread accepts incoming connections , reads once them. calls epoll.register(sock). worker epoll.poll() , further reading , processing of incoming data.

the thing is: if there incoming data short, no more data coming fd after first read done in master thread, worker thread forever blocking in epoll.poll(). should is, should @ least once wake , return newly added file descriptor.

how can this.

my current approach:

master:

worker.epoll.register(sock.fileno()) worker.forced_fds_to_handle.add(sock.fileno()) 

worker:

while true:   fileno, event in self.epoll.poll(1):     self.forced_fds_to_handle.discard(fileno)     self._process(fileno, event)    while self.forced_fds_to_handle:     fileno = self.forced_fds_to_handle.pop()     self._process(fileno, select.epollin) 

what don't approach: in worst case worker ignores incoming fd second means delay clients. of course make timeout smaller somehow waste resources.

i'd appreciate if knew better.

i tried:

in master:

sock.write('') 

... trigger epollin, didn't work.

the default value epoll.poll() -1 , far remembern if enter 0. not wait @ all, check whether there input or not. solve problem.

however, worry of cpu consuming loop while true , no waiting/blocking/sleeping diminish pressure on processor. if find in situation, consider waiting/blocking/sleeping 0.1 seconds , none notice*! ;-) promise... :-)


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -