本文整理汇总了Python中twisted.internet.task.cooperate函数的典型用法代码示例。如果您正苦于以下问题:Python cooperate函数的具体用法?Python cooperate怎么用?Python cooperate使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了cooperate函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: disconnectAll
def disconnectAll(self):
reactor.runUntilCurrent()
def _disconnectAll():
for subscriber in self.connections_ready:
yield subscriber.transport.loseConnection()
task.cooperate(_disconnectAll())
开发者ID:corpaul,项目名称:gumby,代码行数:7,代码来源:sync.py
示例2: main
def main():
print "Starting up..."
state = SharedState()
bot = BotFactory(config, state)
reactor.connectSSL(config.get('server'), config.get('port'), bot, ssl.ClientContextFactory())
cooperate(SlackBot(state, config).listen_to_slack())
reactor.run()
开发者ID:erm,项目名称:slack-irc-bouncer,代码行数:7,代码来源:bot.py
示例3: update_chunks
def update_chunks(self):
x, y, z = self.location.pos.to_block()
x, chaff, z, chaff = split_coords(x, z)
new = set((i + x, j + z) for i, j in circle)
old = set(self.chunks.iterkeys())
added = new - old
discarded = old - new
# Perhaps some explanation is in order.
# The cooperate() function iterates over the iterable it is fed,
# without tying up the reactor, by yielding after each iteration. The
# inner part of the generator expression generates all of the chunks
# around the currently needed chunk, and it sorts them by distance to
# the current chunk. The end result is that we load chunks one-by-one,
# nearest to furthest, without stalling other clients.
if self.chunk_tasks:
for task in self.chunk_tasks:
try:
task.stop()
except (TaskDone, TaskFailed):
pass
self.chunk_tasks = [
cooperate(
self.enable_chunk(i, j) for i, j in
sorted(added, key=lambda t: (t[0] - x)**2 + (t[1] - z)**2)
),
cooperate(self.disable_chunk(i, j) for i, j in discarded)
]
开发者ID:JDShu,项目名称:bravo,代码行数:30,代码来源:protocol.py
示例4: setup
def setup(self):
sb = self.blackboard.bot_standing_on_block(self.blackboard.bot_object)
while sb is None:
yield utils.reactor_break()
sb = self.blackboard.bot_standing_on_block(self.blackboard.bot_object)
else:
if self.travel_multiple_goals is not None:
d = cooperate(AStarMultiCoords(dimension=self.blackboard.dimension,
start_coords=sb.coords,
goal_coords=self.travel_coords,
multiple_goals=self.travel_multiple_goals)).whenDone()
elif self.travel_coords is not None:
d = cooperate(AStarCoords(dimension=self.blackboard.dimension,
start_coords=sb.coords,
goal_coords=self.travel_coords)).whenDone()
else:
d = cooperate(AStarBBCol(dimension=self.blackboard.dimension,
start_coords=sb.coords,
bb=self.travel_bb)).whenDone()
d.addErrback(logbot.exit_on_error)
astar = yield d
if astar.path is not None:
current_start = self.blackboard.bot_standing_on_block(self.blackboard.bot_object)
if sb == current_start:
self.path = astar.path
if self.shorten_path_by > 0:
self.path = self.path[self.shorten_path_by:]
self.start_coords = current_start.coords
开发者ID:Scythic,项目名称:TwistedBot,代码行数:28,代码来源:behavior_tree.py
示例5: pushInfoToSubscribers
def pushInfoToSubscribers(self):
# Generate the json doc
vars = {}
for subscriber in self.connections_ready:
subscriber_vars = subscriber.vars.copy()
subscriber_vars['port'] = subscriber.id + 12000
subscriber_vars['host'] = subscriber.transport.getPeer().host
vars[subscriber.id] = subscriber_vars
json_vars = json.dumps(vars)
del vars
msg("Pushing a %d bytes long json doc." % len(json_vars))
# Send the json doc to the subscribers
task.cooperate(self._sendLineToAllGenerator(json_vars))
开发者ID:corpaul,项目名称:gumby,代码行数:15,代码来源:sync.py
示例6: test_onDisconnect_waitForOutstandingMessagesToFinish
def test_onDisconnect_waitForOutstandingMessagesToFinish(self):
config = self.getConfig(StompSpec.VERSION_1_0)
client = async.Stomp(config)
client.add(ReceiptListener(1.0))
# connect
yield client.connect(host=VIRTUALHOST)
yield task.cooperate(
iter([client.send(self.queue, self.frame, receipt="message-%d" % j) for j in range(self.numMsgs)])
).whenDone()
client.subscribe(
self.queue,
{StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL},
listener=SubscriptionListener(self._frameHandler),
)
# wait for disconnect
yield client.disconnected
# reconnect and subscribe again to make sure that all messages in the queue were ack'ed
yield client.connect(host=VIRTUALHOST)
self.timeExpired = False
self.timeoutDelayedCall = reactor.callLater(1, self._timesUp, client) # @UndefinedVariable
client.subscribe(
self.queue,
{StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL},
listener=SubscriptionListener(self._eatOneFrameAndDisconnect),
)
# wait for disconnect
yield client.disconnected
# time should have expired if there were no messages left in the queue
self.assertTrue(self.timeExpired)
开发者ID:nikipore,项目名称:stompest,代码行数:34,代码来源:async_client_integration_test.py
示例7: startStreaming
def startStreaming(self):
"""
This should be called by the consumer when the producer is registered.
Start streaming data to the consumer.
"""
self._coopTask = cooperate(self._pull())
开发者ID:esabelhaus,项目名称:secret-octo-dubstep,代码行数:7,代码来源:tls.py
示例8: connectionMade
def connectionMade(self):
print("Connected protocol")
self.queue = Queue.Queue()
#self.transport.registerProducer(QueueProducer(self.transport), False)
self.sendLine("3,0,0")
gen = DoodleQueueWorkload(self.transport.reactor, self)
self.task = cooperate(gen)
开发者ID:Yablargo,项目名称:Pyctionary,代码行数:7,代码来源:communicator.py
示例9: searchIndices
def searchIndices(indices, query, period, lastId=None, reverse=False, fields=None, limit=100):
"""
Search the specified indices for events matching the specified query.
:param indices: A list of indices to search.
:type indices: A list of objects implementing :class:`terane.bier.index.IIndex`
:param query: The programmatic query to use for searching the indices.
:type query: An object implementing :class:`terane.bier.searching.IQuery`
:param period: The period within which the search is constrained.
:type period: :class:`terane.bier.searching.Period`
:param lastId: The real key to start iterating from.
:type lastId: :class:`terane.bier.evid.EVID`
:param reverse: If True, then reverse the order of events.
:type reverse: bool
:param fields: If not None, then only return the specified fields of each event.
:type fields: list or None
:param limit: Only returned the specified number of events.
:type limit: int
:returns: A CooperativeTask which contains a Deferred and manages the search task.
:rtype: :class:`twisted.internet.task.CooperativeTask`
"""
start = time.time()
# determine the evids to use as start and end keys
if reverse == False:
startId, endId = period.getRange()
else:
endId, startId = period.getRange()
if lastId != None:
if not lastId in period:
raise SearcherError("lastId %s is not within period" % lastId)
startId = lastId
# search each index separately, then merge the results
try:
searchers = []
postingLists = []
for index in indices:
if not IIndex.providedBy(index):
raise TypeError("index does not implement IIndex")
# we create a copy of the original query, which can possibly be optimized
# with index-specific knowledge.
_query = copy.deepcopy(query)
try:
_query = _query.optimizeMatcher(index)
except NotImplementedError, e:
raise SearcherError(str(e))
logger.debug("optimized query for index '%s': %s" % (index.name, str(_query)))
# if the query optimized out entirely, then skip to the next index
if _query == None:
continue
# get the posting list to iterate through
searcher = index.newSearcher()
if not ISearcher.providedBy(searcher):
raise TypeError("searcher does not implement ISearcher")
postingList = _query.iterMatches(searcher, startId, endId)
if not IPostingList.providedBy(postingList):
raise TypeError("posting list does not implement IPostingList")
searchers.append(searcher)
postingLists.append(postingList)
# return a cooperative task
return cooperate(ResultSet(searchers, postingLists, start, reverse, fields, limit))
开发者ID:DSDev-NickHogle,项目名称:terane,代码行数:60,代码来源:searching.py
示例10: startProducing
def startProducing(self, consumer):
self._consumer = consumer
self._iterable = SmapEncoder().iterencode(self._value)
self._task = cooperate(self._produce())
d = self._task.whenDone()
d.addBoth(self._unregister)
return d
开发者ID:Alwnikrotikz,项目名称:smap-data,代码行数:7,代码来源:sjson.py
示例11: _disconnect
def _disconnect(self, receipt, failure, timeout):
if failure:
self._disconnectReason = failure
self.log.info('Disconnecting ...%s' % ('' if (not failure) else ('[reason=%s]' % failure)))
protocol = self._protocol
try:
# notify that we are ready to disconnect after outstanding messages are ack'ed
if self._messages:
self.log.info('Waiting for outstanding message handlers to finish ... [timeout=%s]' % timeout)
try:
yield task.cooperate(iter([wait(handler, timeout, StompCancelledError('Going down to disconnect now')) for handler in self._messages.values()])).whenDone()
except StompCancelledError as e:
self._disconnectReason = StompCancelledError('Handlers did not finish in time.')
else:
self.log.info('All handlers complete. Resuming disconnect ...')
if self.session.state == self.session.CONNECTED:
frame = self.session.disconnect(receipt)
try:
self.sendFrame(frame)
except Exception as e:
self._disconnectReason = StompConnectionError('Could not send %s. [%s]' % (frame.info(), e))
try:
yield self._waitForReceipt(receipt)
except StompCancelledError:
self._disconnectReason = StompCancelledError('Receipt for disconnect command did not arrive on time.')
protocol.loseConnection()
except Exception as e:
self._disconnectReason = e
开发者ID:irdetoakinavci,项目名称:AMQMessageProducer,代码行数:33,代码来源:client.py
示例12: send_initial_chunk_and_location
def send_initial_chunk_and_location(self):
bigx, smallx, bigz, smallz = split_coords(self.location.x,
self.location.z)
# Spawn the 25 chunks in a square around the spawn, *before* spawning
# the player. Otherwise, there's a funky Beta 1.2 bug which causes the
# player to not be able to move.
d = cooperate(
self.enable_chunk(i, j)
for i, j in product(
xrange(bigx - 3, bigx + 3),
xrange(bigz - 3, bigz + 3)
)
).whenDone()
# Don't dare send more chunks beyond the initial one until we've
# spawned.
d.addCallback(lambda none: self.update_location())
d.addCallback(lambda none: self.position_changed())
# Send the MOTD.
if self.motd:
packet = make_packet("chat",
message=self.motd.replace("<tagline>", get_motd()))
d.addCallback(lambda none: self.transport.write(packet))
# Finally, start the secondary chunk loop.
d.addCallback(lambda none: self.update_chunks())
开发者ID:EntityReborn,项目名称:bravo,代码行数:28,代码来源:beta.py
示例13: startProducing
def startProducing(self, consumer):
""" Must NOT call registerProducer on the consumer """
self._consumer = consumer
self._iterable = json.JSONEncoder().iterencode(self.body)
self._task = cooperate(self._produce())
d = self._task.whenDone()
return d
开发者ID:pantheon-systems,项目名称:tx_clients,代码行数:7,代码来源:web.py
示例14: _driveWorker
def _driveWorker(self, worker, result, testCases, cooperate):
"""
Drive a L{LocalWorkerAMP} instance, iterating the tests and calling
C{run} for every one of them.
@param worker: The L{LocalWorkerAMP} to drive.
@param result: The global L{DistReporter} instance.
@param testCases: The global list of tests to iterate.
@param cooperate: The cooperate function to use, to be customized in
tests.
@type cooperate: C{function}
@return: A C{Deferred} firing when all the tests are finished.
"""
def resultErrback(error, case):
result.original.addFailure(case, error)
return error
def task(case):
d = worker.run(case, result)
d.addErrback(resultErrback, case)
return d
return cooperate(task(case) for case in testCases).whenDone()
开发者ID:12019,项目名称:OpenWrt_Luci_Lua,代码行数:28,代码来源:disttrial.py
示例15: main
def main(reactor, *argv):
parameters = ConnectionParameters.fromCommandLine(reactor, argv)
endpoint = parameters.endpointForCommand(b"/bin/cat")
done = []
factory = Factory()
factory.protocol = Protocol
d = endpoint.connect(factory)
def gotConnection(proto):
conn = proto.transport.conn
for i in range(50):
factory = Factory()
factory.protocol = PrinterProtocol
factory.done = Deferred()
done.append(factory.done)
e = SSHCommandClientEndpoint.existingConnection(
conn, b"/bin/echo %d" % (i,))
yield e.connect(factory)
d.addCallback(gotConnection)
d.addCallback(lambda work: cooperate(work).whenDone())
d.addCallback(lambda ignored: gatherResults(done))
return d
开发者ID:wellbehavedsoftware,项目名称:wbs-graphite,代码行数:27,代码来源:echoclient_shared_ssh.py
示例16: compute
def compute(self, node, recheck=False):
if self.incomplete_nodes:
self.incomplete_nodes[node] = recheck
else:
self.incomplete_nodes[node] = recheck
cootask = cooperate(self.do_incomplete_nodes())
d = cootask.whenDone()
d.addErrback(logbot.exit_on_error)
开发者ID:FrederickGeek8,项目名称:TwistedBot,代码行数:8,代码来源:navigationgrid.py
示例17: _receivedEvent
def _receivedEvent(self, event):
# run the fields through the filter chain, then reschedule the signal
self._input.getContract().validateEventAfter(event, self.parent._fieldstore)
task = cooperate(EventProcessor(event, self._filters, self.parent._fieldstore))
d = task.whenDone()
d.addCallbacks(self._processedEvent, lambda failure: failure)
d.addErrback(self._errorProcessingEvent)
self._scheduleReceivedEvent()
开发者ID:DSDev-NickHogle,项目名称:terane,代码行数:8,代码来源:routes.py
示例18: begin
def begin(self, consumer):
self._consumer=consumer
self._iterable=JSONEncoder().iterencode(self._value)
self._consumer.registerProducer(self, True)
self._task=cooperate(self._produce())
defer=self._task.whenDone()
defer.addBoth(self._unregister)
return defer
开发者ID:DamnWidget,项目名称:goliat,代码行数:8,代码来源:asyncjson.py
示例19: wrapper
def wrapper(n):
def stop_task(unused_deferred):
try: t.stop()
except task.TaskFailed: pass
d = defer.Deferred(canceller=stop_task)
t = task.cooperate(cooperator(func(n), n+1,
yield_interval, d.callback))
return d
开发者ID:zed,项目名称:txfib,代码行数:8,代码来源:fibonacci.py
示例20: main
def main(res):
"""
Go main Go!
"""
log.msg("main() fired!")
jobs = DeferredQueue()
ingest = MyProductIngestor()
ingest.jobs = jobs
ldmbridge.LDMProductFactory(ingest)
for _ in range(6):
cooperate(worker(jobs))
lc = LoopingCall(save_current)
lc.start(373, now=False)
lc2 = LoopingCall(service_guard, jobs)
lc2.start(61, now=False)
开发者ID:akrherz,项目名称:pyWWA,代码行数:17,代码来源:shef_parser.py
注:本文中的twisted.internet.task.cooperate函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论