本文整理匯總了Python中twisted.internet.error.ReactorAlreadyRunning方法的典型用法代碼示例。如果您正苦於以下問題:Python error.ReactorAlreadyRunning方法的具體用法?Python error.ReactorAlreadyRunning怎麽用?Python error.ReactorAlreadyRunning使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類twisted.internet.error
的用法示例。
在下文中一共展示了error.ReactorAlreadyRunning方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: startRunning
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def startRunning(self):
"""
Method called when reactor starts: do some initialization and fire
startup events.
Don't call this directly, call reactor.run() instead: it should take
care of calling this.
This method is somewhat misnamed. The reactor will not necessarily be
in the running state by the time this method returns. The only
guarantee is that it will be on its way to the running state.
"""
if self._started:
raise error.ReactorAlreadyRunning()
if self._startedBefore:
raise error.ReactorNotRestartable()
self._started = True
self._stopped = False
if self._registerAsIOThread:
threadable.registerAsIOThread()
self.fireSystemEvent('startup')
示例2: test_cantRegisterAfterRun
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def test_cantRegisterAfterRun(self):
"""
It is not possible to register a C{Application} after the reactor has
already started.
"""
reactor = gireactor.GIReactor(useGtk=False)
self.addCleanup(self.unbuildReactor, reactor)
app = Gio.Application(
application_id='com.twistedmatrix.trial.gireactor',
flags=Gio.ApplicationFlags.FLAGS_NONE)
def tryRegister():
exc = self.assertRaises(ReactorAlreadyRunning,
reactor.registerGApplication, app)
self.assertEqual(exc.args[0],
"Can't register application after reactor was started.")
reactor.stop()
reactor.callLater(0, tryRegister)
ReactorBuilder.runReactor(self, reactor)
示例3: startRunning
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def startRunning(self):
"""
Method called when reactor starts: do some initialization and fire
startup events.
Don't call this directly, call reactor.run() instead: it should take
care of calling this.
This method is somewhat misnamed. The reactor will not necessarily be
in the running state by the time this method returns. The only
guarantee is that it will be on its way to the running state.
"""
if self._started:
raise error.ReactorAlreadyRunning()
self._started = True
self._stopped = False
threadable.registerAsIOThread()
self.fireSystemEvent('startup')
示例4: run
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def run(self):
try:
reactor.run(installSignalHandlers=False)
except ReactorAlreadyRunning:
# Ignore error about reactor already running
pass
示例5: registerGApplication
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def registerGApplication(self, app):
"""
Register a C{Gio.Application} or C{Gtk.Application}, whose main loop
will be used instead of the default one.
We will C{hold} the application so it doesn't exit on its own. In
versions of C{python-gi} 3.2 and later, we exit the event loop using
the C{app.quit} method which overrides any holds. Older versions are
not supported.
"""
if self._gapplication is not None:
raise RuntimeError(
"Can't register more than one application instance.")
if self._started:
raise ReactorAlreadyRunning(
"Can't register application after reactor was started.")
if not hasattr(app, "quit"):
raise RuntimeError("Application registration is not supported in"
" versions of PyGObject prior to 3.2.")
self._gapplication = app
def run():
app.hold()
app.run(None)
self._run = run
self._crash = app.quit
示例6: test_multipleRun
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def test_multipleRun(self):
"""
C{reactor.run()} raises L{ReactorAlreadyRunning} when called when
the reactor is already running.
"""
events = []
def reentrantRun():
self.assertRaises(ReactorAlreadyRunning, reactor.run)
events.append("tested")
reactor = self.buildReactor()
reactor.callWhenRunning(reentrantRun)
reactor.callWhenRunning(reactor.stop)
self.runReactor(reactor)
self.assertEqual(events, ["tested"])
示例7: connect_to_socket
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def connect_to_socket(port, observers=None):
if port is None:
raise ValueError('port', port)
api_server = token_ops.get_api_server()
if api_server is not None:
if api_server.startswith('https://'):
api_server = api_server.replace('https://', 'wss://')
if api_server.endswith('/'):
api_server = api_server[:-1]
url = api_server + ':' + str(port)
logging.info('connect_to_socket')
logging.info('Establishing socket connection: %s' % url)
factory = WebSocketClientFactory(url)
factory.protocol = IQStreamer
connectWS(factory)
if observers is not None:
publisher = StreamPublisher()
for obs in observers:
publisher.register(obs)
try:
factory.reactor.run(installSignalHandlers=False)
except error.ReactorAlreadyRunning:
pass
示例8: test_multipleRun
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def test_multipleRun(self):
"""
C{reactor.run()} raises L{ReactorAlreadyRunning} when called when
the reactor is already running.
"""
events = []
def reentrantRun():
self.assertRaises(ReactorAlreadyRunning, reactor.run)
events.append("tested")
reactor = self.buildReactor()
reactor.callWhenRunning(reentrantRun)
reactor.callWhenRunning(reactor.stop)
reactor.run()
self.assertEqual(events, ["tested"])
示例9: start_process
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def start_process(process, stop_after_job):
try:
process.start(stop_after_job)
except ReactorAlreadyRunning:
pass
示例10: start
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def start(self):
site = server.Site(AdminPage(self))
reactor.listenTCP(port, site)
logger.log(logging.INFO,
"Now listening for connections on port %d...",
port)
try:
if not reactor.running:
reactor.run(installSignalHandlers=0)
except ReactorAlreadyRunning:
pass
示例11: start
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def start(self):
endpoint = serverFromString(
reactor,
"tcp:%d:interface=%s" % (address[1], address[0])
)
conn = endpoint.listen(PlayerFactory())
try:
if not reactor.running:
reactor.run(installSignalHandlers=0)
except ReactorAlreadyRunning:
pass
示例12: start
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def start(self):
site = server.Site(RegPage(self))
reactor.listenTCP(port, site)
logger.log(logging.INFO,
"Now listening for connections on port %d...",
port)
try:
if not reactor.running:
reactor.run(installSignalHandlers=0)
except ReactorAlreadyRunning:
pass
示例13: start
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def start(self):
endpoint_search = serverFromString(
reactor,
"tcp:%d:interface=%s" % (address[1], address[0])
)
conn_search = endpoint_search.listen(GamestatsFactory())
try:
if not reactor.running:
reactor.run(installSignalHandlers=0)
except ReactorAlreadyRunning:
pass
示例14: start
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def start(self):
endpoint_search = serverFromString(
reactor,
"tcp:%d:interface=%s" % (address[1], address[0])
)
conn_search = endpoint_search.listen(PlayerSearchFactory())
try:
if not reactor.running:
reactor.run(installSignalHandlers=0)
except ReactorAlreadyRunning:
pass
示例15: start
# 需要導入模塊: from twisted.internet import error [as 別名]
# 或者: from twisted.internet.error import ReactorAlreadyRunning [as 別名]
def start(self):
endpoint = serverFromString(
reactor, "tcp:%d:interface=%s" % (address[1], address[0])
)
conn = endpoint.listen(SessionFactory(self.qr))
try:
if not reactor.running:
reactor.run(installSignalHandlers=0)
except ReactorAlreadyRunning:
pass