本文整理汇总了Python中twisted.internet.reactor.callLater函数的典型用法代码示例。如果您正苦于以下问题:Python callLater函数的具体用法?Python callLater怎么用?Python callLater使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了callLater函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:Almad,项目名称:twisted,代码行数:7,代码来源:test_sftp.py
示例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!'
开发者ID:kmcintyre,项目名称:gardenpath,代码行数:7,代码来源:alexa.py
示例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)
开发者ID:jcollie,项目名称:txrdq,代码行数:27,代码来源:test_rdq.py
示例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)
开发者ID:skierkyles,项目名称:TISCaP_Client,代码行数:7,代码来源:main.py
示例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()
开发者ID:cool-shark,项目名称:crashxmpp,代码行数:7,代码来源:crashxmpp.py
示例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)
开发者ID:pwarren,项目名称:AGDeviceControl,代码行数:29,代码来源:test_util.py
示例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)
开发者ID:bibinjose22,项目名称:daphne,代码行数:7,代码来源:server.py
示例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()
开发者ID:NurKaynar,项目名称:hacklab,代码行数:30,代码来源:sender.py
示例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)
开发者ID:elmore,项目名称:sixthdev,代码行数:7,代码来源:gamed.py
示例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
开发者ID:Callek,项目名称:buildbot,代码行数:7,代码来源:libvirtbuildslave.py
示例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)
开发者ID:BPzeBanshee,项目名称:Arc,代码行数:27,代码来源:worldutil.py
示例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)
开发者ID:twonds,项目名称:idavoll,代码行数:35,代码来源:gateway.py
示例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))
开发者ID:anson-tang,项目名称:3dkserver,代码行数:27,代码来源:attribute.py
示例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)
开发者ID:biddyweb,项目名称:crossbar,代码行数:7,代码来源:process.py
示例15: closedown
def closedown(self):
self.stopService()
try:
reactor.callLater(0.5,reactor.stop)
# reactor.stop()
except ReactorNotRunning:
pass
开发者ID:aquamatt,项目名称:Peloton,代码行数:7,代码来源:worker.py
示例16: test_quick_restart
def test_quick_restart(self):
"Testing for #68, restarting quickly a connector will loose its session state"
# Add a connector and start it
extraCommands = [{'command': 'cid operator_1'},
{'command': 'port %s' % self.SMSCPort.getHost().port},]
yield self.add_connector(r'jcli : ', extraCommands)
yield self.start_connector('operator_1', wait = 3)
# List and assert it is BOUND
expectedList = ['#Connector id Service Session Starts Stops',
'#operator_1 started BOUND_TRX 1 0 ',
'Total connectors: 1']
commands = [{'command': 'smppccm -l', 'expect': expectedList}]
yield self._test(r'jcli : ', commands)
# Stop and start very quickly will lead to an error starting the connector because there were
# no sufficient time for unbind to complete
yield self.stop_connector('operator_1', finalPrompt = None, wait = 0)
yield self.start_connector('operator_1', finalPrompt = None,
wait = 0,
expect= 'Failed starting connector, check log for details')
# Wait
exitDeferred = defer.Deferred()
reactor.callLater(2, exitDeferred.callback, None)
yield exitDeferred
# List and assert it is stopped (start command errored)
expectedList = ['#Connector id Service Session Starts Stops',
'#operator_1 stopped NONE 1 1 ',
'Total connectors: 1']
commands = [{'command': 'smppccm -l', 'expect': expectedList}]
yield self._test(r'jcli : ', commands)
开发者ID:Baalmart,项目名称:jasmin,代码行数:34,代码来源:test_smppccm.py
示例17: _maybe_retry
def _maybe_retry(e):
log.err()
if attempt < self.max_attempts:
reactor.callLater(attempt * self.retry_multiplier,
self._retrying_fetch, u, data, event, attempt + 1)
else:
return e
开发者ID:MPanH,项目名称:buildbot,代码行数:7,代码来源:webhook_status.py
示例18: print_traffic
def print_traffic():
self.log.info("Traffic {}: {} / {} in / out bytes - {} / {} in / out msgs".format(self.peer,
self.trafficStats.incomingOctetsWireLevel,
self.trafficStats.outgoingOctetsWireLevel,
self.trafficStats.incomingWebSocketMessages,
self.trafficStats.outgoingWebSocketMessages))
reactor.callLater(1, print_traffic)
开发者ID:Paranaix,项目名称:crossbar,代码行数:7,代码来源:protocol.py
示例19: render
def render(self, request):
now = time()
delta = now - self.lasttime
# reset stats on high iter-request times caused by client restarts
if delta > 3: # seconds
self._reset_stats()
return ''
self.tail.appendleft(delta)
self.lasttime = now
self.concurrent += 1
if now - self.lastmark >= 3:
self.lastmark = now
qps = len(self.tail) / sum(self.tail)
print('samplesize={0} concurrent={1} qps={2:0.2f}'.format(len(self.tail), self.concurrent, qps))
if 'latency' in request.args:
latency = float(request.args['latency'][0])
reactor.callLater(latency, self._finish, request)
return NOT_DONE_YET
self.concurrent -= 1
return ''
开发者ID:jtwaleson,项目名称:scrapy,代码行数:25,代码来源:qps-bench-server.py
示例20: _processQueue
def _processQueue(self):
def processFinished(value, processProtocol):
self._num_running -= 1
reactor.callLater(0, self._processQueue)
execTime = processProtocol.execStopTime - processProtocol.execStartTime
qTime = processProtocol.queueStopTime - processProtocol.queueStartTime
self._maxQtime = max(self._maxQtime, qTime)
self._maxExecTime = max(self._maxExecTime, execTime)
log.debug("execution time %s seconds; queue time %s seconds; "
"process %s"
% ( execTime, qTime, processProtocol))
if (self._num_running == 0
and self._stopped
and not self._stopped.called
and len(self._processes) == 0):
self._stopped.callback("process queue is empty and stopped")
log.debug("Number of process being executed: %s" % self._num_running)
if self._num_running < self._parallel:
processQProtocol = None
if self._processes:
processQProtocol = self._processes.popleft()
if processQProtocol:
self._num_running += 1
d = processQProtocol.start()
d.addBoth(processFinished, processQProtocol)
if self._processes and self._num_running < self._parallel:
reactor.callLater(0, self._processQueue)
return
开发者ID:bbc,项目名称:zenoss-prodbin,代码行数:30,代码来源:ProcessQueue.py
注:本文中的twisted.internet.reactor.callLater函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论