def _plexMainLoop(self): s_threads.iCantWait(name='SynPlexMain') while not self.isfini: try: rxlist, txlist, xxlist = select.select(self._plex_rxsocks, self._plex_txsocks, self._plex_rxsocks, 0.2) except Exception as e: # go through ALL of our rx sockets, and call fini() on the # sock if those sockets fileno() call is -1 # The .copy() method is used since it is faster for small lists. logger.exception( 'Error during socket select. Culling fini or fileno==-1 sockets.' ) [ sock.fini() for sock in self._plex_rxsocks.copy() if sock.fileno() == -1 ] continue try: for rxsock in rxlist: if rxsock.get('wake'): rxsock.recv(10240) continue # if he's a listen sock... accept() if rxsock.get('listen'): connsock, connaddr = rxsock.accept() if connsock is not None: self.addPlexSock(connsock) self.fire('link:sock:init', sock=connsock) continue # yield any completed mesgs for mesg in rxsock.rx(): self.fire('link:sock:mesg', sock=rxsock, mesg=mesg) for txsock in txlist: if not txsock.runTxLoop(): txsock.set('plex:istx', False) try: self._plex_txsocks.remove(txsock) except ValueError as e: pass [self._finiPlexSock(sock) for sock in xxlist] except Exception as e: logger.warning('plexMainLoop: %s', e)
def test_threads_cantwait(self): self.true(s_threads.iMayWait()) s_threads.iCantWait() self.false(s_threads.iMayWait()) self.raises(MustNotWait, s_threads.iWillWait) del threading.currentThread()._syn_cantwait self.true(s_threads.iMayWait())
def test_threads_cantwait(self): self.assertTrue( s_threads.iMayWait() ) s_threads.iCantWait() self.assertFalse( s_threads.iMayWait() ) self.assertRaises(MustNotWait, s_threads.iWillWait) del threading.currentThread()._syn_cantwait self.assertTrue( s_threads.iMayWait() )
def _plexMainLoop(self): s_threads.iCantWait(name='SynPlexMain') while not self.isfini: try: rxlist, txlist, xxlist = select.select(self._plex_rxsocks, self._plex_txsocks, self._plex_xxsocks, 0.2) except Exception as e: # go through ALL of our sockets, and call _finiPlexSock on that socket if it has been fini'd or # if those sockets fileno() call is -1 # The .copy() method is used since it is faster for small lists. # The identity check of -1 is reliant on a CPython optimization which keeps a single # addressed copy of integers between -5 and 256 in. memory logger.exception('Error during socket select. Culling fini or fileno==-1 sockets.') [self._finiPlexSock(sck) for sck in self._plex_rxsocks.copy() if sck.isfini or sck.fileno() is -1] continue try: for rxsock in rxlist: if rxsock.get('wake'): rxsock.recv(10240) continue # if he's a listen sock... accept() if rxsock.get('listen'): connsock, connaddr = rxsock.accept() if connsock is not None: self.addPlexSock(connsock) self.fire('link:sock:init', sock=connsock) continue # yield any completed mesgs for mesg in rxsock.rx(): self.fire('link:sock:mesg', sock=rxsock, mesg=mesg) for txsock in txlist: if not txsock.runTxLoop(): txsock.set('plex:istx', False) try: self._plex_txsocks.remove(txsock) except ValueError as e: pass [self._finiPlexSock(sock) for sock in xxlist] except Exception as e: logger.warning('plexMainLoop: %s', e)
def _plexMainLoop(self): s_threads.iCantWait(name='SynPlexMain') while not self.isfini: try: rxlist, txlist, xxlist = select.select(self._plex_rxsocks, self._plex_txsocks, self._plex_xxsocks, 0.2) # mask "bad file descriptor" race and go around again... except Exception as e: continue try: for rxsock in rxlist: if rxsock.get('wake'): rxsock.recv(10240) continue # if he's a listen sock... accept() if rxsock.get('listen'): connsock, connaddr = rxsock.accept() if connsock is not None: self.addPlexSock(connsock) self.fire('link:sock:init', sock=connsock) continue # yield any completed mesgs for mesg in rxsock.rx(): self.fire('link:sock:mesg', sock=rxsock, mesg=mesg) for txsock in txlist: if not txsock.runTxLoop(): txsock.set('plex:istx', False) try: self._plex_txsocks.remove(txsock) except ValueError as e: pass [sock.fini() for sock in xxlist] except Exception as e: logger.warning('plexMainLoop: %s', e)
def _plexMainLoop(self): s_threads.iCantWait(name='SynPlexMain') while not self.isfini: try: rxlist,txlist,xxlist = select.select(self._plex_rxsocks,self._plex_txsocks,self._plex_xxsocks,0.2) # mask "bad file descriptor" race and go around again... except Exception as e: continue try: for rxsock in rxlist: if rxsock.get('wake'): rxsock.recv(10240) continue # if he's a listen sock... accept() if rxsock.get('listen'): connsock,connaddr = rxsock.accept() if connsock != None: rxsock.fire('link:sock:init', sock=connsock) continue # yield any completed mesgs for mesg in rxsock.rx(): rxsock.fire('link:sock:mesg', sock=rxsock, mesg=mesg) for txsock in txlist: self._runSockTx(txsock) [ sock.fini() for sock in xxlist ] except Exception as e: logger.warning('plexMainLoop: %s', e)