本文整理汇总了Python中twisted.internet.reactor.removeReader方法的典型用法代码示例。如果您正苦于以下问题:Python reactor.removeReader方法的具体用法?Python reactor.removeReader怎么用?Python reactor.removeReader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.internet.reactor
的用法示例。
在下文中一共展示了reactor.removeReader方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_listener_ignores_ENOENT_when_removing_itself_from_reactor
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import removeReader [as 别名]
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))
示例2: connectionMade
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import removeReader [as 别名]
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)
示例3: connectionMade
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import removeReader [as 别名]
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)
示例4: stopReading
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import removeReader [as 别名]
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
示例5: test_doRead_removes_self_from_reactor_on_error
# 需要导入模块: from twisted.internet import reactor [as 别名]
# 或者: from twisted.internet.reactor import removeReader [as 别名]
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))