Python twisted.internet.reactor.removeReader() Examples
The following are 7
code examples of twisted.internet.reactor.removeReader().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
twisted.internet.reactor
, or try the search function
.
Example #1
Source File: test_listener.py From maas with GNU Affero General Public License v3.0 | 6 votes |
def test_listener_ignores_ENOENT_when_removing_itself_from_reactor(self): listener = PostgresListenerService() self.patch(reactor, "addReader") self.patch(reactor, "removeReader") # removeReader() is going to have a nasty accident. enoent = IOError("ENOENT") enoent.errno = errno.ENOENT reactor.removeReader.side_effect = enoent # The listener starts and stops without issue. yield listener.startService() yield listener.stopService() # addReader() and removeReader() were both called. self.assertThat(reactor.addReader, MockCalledOnceWith(listener)) self.assertThat(reactor.removeReader, MockCalledOnceWith(listener))
Example #2
Source File: inetd.py From Safejumper-for-Desktop with GNU General Public License v2.0 | 5 votes |
def connectionMade(self): sockFD = self.transport.fileno() childFDs = {0: sockFD, 1: sockFD} if self.factory.stderrFile: childFDs[2] = self.factory.stderrFile.fileno() # processes run by inetd expect blocking sockets # FIXME: maybe this should be done in process.py? are other uses of # Process possibly affected by this? fdesc.setBlocking(sockFD) if 2 in childFDs: fdesc.setBlocking(childFDs[2]) service = self.factory.service uid = service.user gid = service.group # don't tell Process to change our UID/GID if it's what we # already are if uid == os.getuid(): uid = None if gid == os.getgid(): gid = None process.Process(None, service.program, service.programArgs, os.environ, None, None, uid, gid, childFDs) reactor.removeReader(self.transport) reactor.removeWriter(self.transport)
Example #3
Source File: inetd.py From learn_python3_spider with MIT License | 5 votes |
def connectionMade(self): sockFD = self.transport.fileno() childFDs = {0: sockFD, 1: sockFD} if self.factory.stderrFile: childFDs[2] = self.factory.stderrFile.fileno() # processes run by inetd expect blocking sockets # FIXME: maybe this should be done in process.py? are other uses of # Process possibly affected by this? fdesc.setBlocking(sockFD) if 2 in childFDs: fdesc.setBlocking(childFDs[2]) service = self.factory.service uid = service.user gid = service.group # don't tell Process to change our UID/GID if it's what we # already are if uid == os.getuid(): uid = None if gid == os.getgid(): gid = None process.Process(None, service.program, service.programArgs, os.environ, None, None, uid, gid, childFDs) reactor.removeReader(self.transport) reactor.removeWriter(self.transport)
Example #4
Source File: inetd.py From python-for-android with Apache License 2.0 | 5 votes |
def connectionMade(self): sockFD = self.transport.fileno() childFDs = {0: sockFD, 1: sockFD} if self.factory.stderrFile: childFDs[2] = self.factory.stderrFile.fileno() # processes run by inetd expect blocking sockets # FIXME: maybe this should be done in process.py? are other uses of # Process possibly affected by this? fdesc.setBlocking(sockFD) if childFDs.has_key(2): fdesc.setBlocking(childFDs[2]) service = self.factory.service uid = service.user gid = service.group # don't tell Process to change our UID/GID if it's what we # already are if uid == os.getuid(): uid = None if gid == os.getgid(): gid = None process.Process(None, service.program, service.programArgs, os.environ, None, None, uid, gid, childFDs) reactor.removeReader(self.transport) reactor.removeWriter(self.transport)
Example #5
Source File: inetd.py From BitTorrent with GNU General Public License v3.0 | 5 votes |
def connectionMade(self): sockFD = self.transport.fileno() childFDs = {0: sockFD, 1: sockFD} if self.factory.stderrFile: childFDs[2] = self.factory.stderrFile.fileno() # processes run by inetd expect blocking sockets # FIXME: maybe this should be done in process.py? are other uses of # Process possibly affected by this? fdesc.setBlocking(sockFD) if childFDs.has_key(2): fdesc.setBlocking(childFDs[2]) service = self.factory.service uid = service.user gid = service.group # don't tell Process to change our UID/GID if it's what we # already are if uid == os.getuid(): uid = None if gid == os.getgid(): gid = None process.Process(None, service.program, service.programArgs, os.environ, None, None, uid, gid, childFDs) reactor.removeReader(self.transport) reactor.removeWriter(self.transport)
Example #6
Source File: listener.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def stopReading(self): """Remove this listener from the reactor.""" try: reactor.removeReader(self) except IOError as error: # ENOENT here means that the fd has already been unregistered # from the underlying poller. It is as yet unclear how we get # into this state, so for now we ignore it. See epoll_ctl(2). if error.errno != ENOENT: raise finally: self.connectionFileno = None
Example #7
Source File: test_listener.py From maas with GNU Affero General Public License v3.0 | 5 votes |
def test_doRead_removes_self_from_reactor_on_error(self): listener = PostgresListenerService() connection = self.patch(listener, "connection") connection.connection.poll.side_effect = OperationalError() self.patch(reactor, "removeReader") self.patch(listener, "connectionLost") failure = listener.doRead() # No failure is returned; see the comment in # PostgresListenerService.doRead() that explains why we don't do that. self.assertThat(failure, Is(None)) # The listener has begun disconnecting. self.assertThat(listener.disconnecting, IsInstance(Deferred)) # Wait for disconnection to complete. yield listener.disconnecting # The listener has removed itself from the reactor. self.assertThat(reactor.removeReader, MockCalledOnceWith(listener)) # connectionLost() has been called with a simple ConnectionLost. self.assertThat(listener.connectionLost, MockCalledOnceWith(ANY)) [failure] = listener.connectionLost.call_args[0] self.assertThat(failure, IsInstance(Failure)) self.assertThat(failure.value, IsInstance(error.ConnectionLost))