本文整理汇总了Python中twisted.internet.reactor.callLater函数的典型用法代码示例。如果您正苦于以下问题:Python callLater函数的具体用法?Python callLater怎么用?Python callLater使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了callLater函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createDirectory
def createDirectory(self, childName):
d = defer.Deferred()
d2 = defer.maybeDeferred(inmem.FakeDirectory.createDirectory,
self, childName)
from twisted.internet import reactor
reactor.callLater(1, d2.chainDeferred, d)
return d
示例2: launch
def launch(howmany):
print 'launch' + str(howmany)
if howmany > 0:
loop('test' + str(howmany), Gardener())
reactor.callLater(1, lambda: launch(howmany - 1))
elif howmany == 0:
print 'done!'
示例3: testStopAndCancelWithOneUnderway
def testStopAndCancelWithOneUnderway(self):
"""
Start a dispatch queue of width 2, and send it 3 jobs. Verify that
2 of the jobs are underway. Then stop it before they can complete,
telling it to cancel the underway jobs. The two jobs that were
underway should both be cancelled and returned by the stop method.
The first 2 jobs returned should have state CANCELLED, and the
final one should still be PENDING.
"""
def ok(result):
self.fail('Unexpected success!')
def checkCancel(failure):
self.assertEqual(failure.value.state, Job.CANCELLED)
dq = ResizableDispatchQueue(self.slow, 2)
dq.put(0).addCallbacks(ok, checkCancel)
dq.put(1).addCallbacks(ok, checkCancel)
dq.put(2)
reactor.callLater(0.01, self._testUnderway, dq, set([0, 1]))
pendingJobs = yield task.deferLater(
reactor, 0.1, dq.stop, cancelUnderway=True)
pendingArgs = [p.jobarg for p in pendingJobs]
self.assertEqual([0, 1, 2], sorted(pendingArgs))
self.assertEqual(pendingJobs[0].state, Job.CANCELLED)
self.assertEqual(pendingJobs[1].state, Job.CANCELLED)
self.assertEqual(pendingJobs[2].state, Job.PENDING)
示例4: try_login
def try_login(self, uname):
if (self.cf.instance != None):
self.cf.instance.login(uname)
self.uname = uname
return True
reactor.callLater(0.25, self.try_login, uname)
示例5: start
def start(self):
myJid = jid.JID(self.username)
factory = client.XMPPClientFactory(myJid, self.password)
factory.addBootstrap(xmlstream.STREAM_AUTHD_EVENT, self.authd)
connector = SRVConnector(reactor, 'xmpp-client', self.jabberserver, factory)
reactor.callLater(5, self.stop)
connector.connect()
示例6: testKeyboardInterrupt
def testKeyboardInterrupt(self):
# Test the KeyboardInterrupt is *not* caught by wait -- we
# want to allow users to Ctrl-C test runs. And the use of the
# useWaitError should not matter in this case.
def raiseKeyInt(ignored):
# XXX Abstraction violation, I suppose. However: signals are
# unreliable, so using them to simulate a KeyboardInterrupt
# would be sketchy too; os.kill() is not available on Windows,
# so we can't use that and let this run on Win32; raising
# KeyboardInterrupt itself is wholely unrealistic, as the
# reactor would normally block SIGINT for its own purposes and
# not allow a KeyboardInterrupt to happen at all!
if interfaces.IReactorThreads.providedBy(reactor):
reactor.callInThread(reactor.sigInt)
else:
reactor.callLater(0, reactor.sigInt)
return defer.Deferred()
d = defer.Deferred()
d.addCallback(raiseKeyInt)
reactor.callLater(0, d.callback, True)
self.assertRaises(KeyboardInterrupt, util.wait, d, useWaitError=False)
d = defer.Deferred()
d.addCallback(raiseKeyInt)
reactor.callLater(0, d.callback, True)
self.assertRaises(KeyboardInterrupt, util.wait, d, useWaitError=True)
示例7: timeout_checker
def timeout_checker(self):
"""
Called periodically to enforce timeout rules on all connections.
Also checks pings at the same time.
"""
self.factory.check_timeouts()
reactor.callLater(2, self.timeout_checker)
示例8: connected
def connected(self, msg):
"""Once I've connected I want to subscribe to my the message queue.
"""
stomper.Engine.connected(self, msg)
self.log.info("senderID:%s Connected: session %s." % (
self.senderID,
msg['headers']['session'])
)
# I originally called loopingCall(self.send) directly, however it turns
# out that we had not fully subscribed. This meant we did not receive
# out our first send message. I fixed this by using reactor.callLater
#
#
def setup_looping_call():
lc = LoopingCall(self.send)
lc.start(2)
reactor.callLater(1, setup_looping_call)
f = stomper.Frame()
f.unpack(stomper.subscribe(DESTINATION))
# ActiveMQ specific headers:
#
# prevent the messages we send comming back to us.
f.headers['activemq.noLocal'] = 'true'
return f.pack()
示例9: __init__
def __init__(self):
self.clients = []
self.game = Game()
self.mob = Actor("eeeeeeewwwwwww")
self.game.place(self.mob, (1,1))
self.game.register(self.on_notify)
reactor.callLater(1, self.tick)
示例10: _work_done
def _work_done(res):
log.msg("Completed a piece of work")
self.queue.pop(0)
if self.queue:
log.msg("Preparing next piece of work")
reactor.callLater(0, self._process)
return res
示例11: commandRestore
def commandRestore(self, parts, fromloc, overriderank):
"/restore worldname number - Op\nRestore world to indicated number."
if len(parts) < 2:
self.client.sendServerMessage("Please specify at least a world ID!")
else:
world_id = parts[1].lower()
world_dir = ("worlds/%s/" % world_id)
if len(parts) < 3:
backups = os.listdir(world_dir + "backup/")
backups.sort(lambda x, y: int(x) - int(y))
backup_number = str(int(backups[-1]))
else:
backup_number = parts[2]
if not os.path.exists(world_dir + "backup/%s/" % backup_number):
self.client.sendServerMessage("Backup %s does not exist." % backup_number)
else:
if not os.path.exists(world_dir + "blocks.gz.new"):
shutil.copy((world_dir + "backup/%s/blocks.gz" % backup_number), world_dir)
if os.path.exists(world_dir + "backup/%s/world.meta" % backup_number):
shutil.copy((world_dir + "backup/%s/world.meta" % backup_number), world_dir)
else:
reactor.callLater(1, self.commandRestore, self, parts, fromloc, overriderank)
self.client.factory.unloadWorld(world_id, skiperror=True)
self.client.sendServerMessage("%s has been restored to %s and booted." % (world_id, backup_number))
if world_id in self.client.factory.worlds:
for client in self.client.factory.worlds[world_id].clients:
client.changeToWorld(world_id)
示例12: _postTo
def _postTo(self, callbacks, service, nodeIdentifier,
payload=None, contentType=None, eventType=None,
redirectURI=None):
if not callbacks:
return
postdata = None
nodeURI = getXMPPURI(service, nodeIdentifier)
headers = {'Referer': nodeURI.encode('utf-8'),
'PubSub-Service': service.full().encode('utf-8')}
if payload:
postdata = payload.toXml().encode('utf-8')
if contentType:
headers['Content-Type'] = "%s;charset=utf-8" % contentType
if eventType:
headers['Event'] = eventType
if redirectURI:
headers['Link'] = '<%s>; rel=alternate' % (
redirectURI.encode('utf-8'),
)
def postNotification(callbackURI):
f = getPageWithFactory(str(callbackURI),
method='POST',
postdata=postdata,
headers=headers)
d = f.deferred
d.addErrback(log.err)
for callbackURI in callbacks:
reactor.callLater(0, postNotification, callbackURI)
示例13: sync_dirty_attributes
def sync_dirty_attributes(queue, loop=True):
_l = queue.qsize()
if _l > 0:
if loop:
_times = min(_l, MAX_SYNC_CNT_PER_LOOP)
else:
_times = _l
i = 0
while i < _times:
i += 1
try:
attr = queue.get_nowait()
attr.syncdb()
except Queue.Empty:
break
except:
pass
log.info('End sync character to db, total: {0}, dirty attributes length: {1}'.format( _times, queue.qsize() ))
if loop:
reactor.callLater(SYNC_DB_INTERVAL, sync_dirty_attributes, queue)
else:
log.debug('End sync db, dirty attributes length {0}, loop:{1}'.format(
queue.qsize(), loop))
示例14: on_fsevent
def on_fsevent(evt):
worker.watcher.stop()
proto.signal('TERM')
if options['watch'].get('action', None) == 'restart':
log.msg("Restarting guest ..")
reactor.callLater(0.1, self.start_guest, id, config, details)
示例15: closedown
def closedown(self):
self.stopService()
try:
reactor.callLater(0.5,reactor.stop)
# reactor.stop()
except ReactorNotRunning:
pass