当前位置: 首页>>代码示例>>Python>>正文


Python DeferredList.addBoth方法代码示例

本文整理汇总了Python中twisted.internet.defer.DeferredList.addBoth方法的典型用法代码示例。如果您正苦于以下问题:Python DeferredList.addBoth方法的具体用法?Python DeferredList.addBoth怎么用?Python DeferredList.addBoth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.internet.defer.DeferredList的用法示例。


在下文中一共展示了DeferredList.addBoth方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: cleanUp

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
    def cleanUp(self, wasClean, code, reason):
        """Thorough clean-up method to cancel all remaining deferreds, and send
        connection metrics in"""
        self.ps.metrics.increment("client.socket.disconnect", tags=self.base_tags)
        elapsed = (ms_time() - self.ps.connected_at) / 1000.0
        self.ps.metrics.timing("client.socket.lifespan", duration=elapsed, tags=self.base_tags)

        # Cleanup our client entry
        if self.ps.uaid and self.ap_settings.clients.get(self.ps.uaid) == self:
            del self.ap_settings.clients[self.ps.uaid]

        # Cancel any outstanding deferreds that weren't already called
        for d in self.ps._callbacks:
            if not d.called:
                d.cancel()

        # Attempt to deliver any notifications not originating from storage
        if self.ps.direct_updates:
            defers = []
            if self.ps.use_webpush:
                for notifs in self.ps.direct_updates.values():
                    notifs = filter(lambda x: x.ttl != 0, notifs)
                    defers.extend(map(self._save_webpush_notif, notifs))
            else:
                for chid, version in self.ps.direct_updates.items():
                    defers.append(self._save_simple_notif(chid, version))

            # Tag on the notifier once everything has been stored
            dl = DeferredList(defers)
            dl.addBoth(self._lookup_node)

        # Delete and remove remaining dicts and lists
        del self.ps.direct_updates
        del self.ps.updates_sent
开发者ID:ncalexan,项目名称:autopush,代码行数:36,代码来源:websocket.py

示例2: provision

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
    def provision(self, request):
        """
        Provision the device with credentials from a cloud controller.
        """
        cors.config_cors(request)
        body = json.loads(request.content.read().decode('utf-8'))
        routerId = body['routerId']
        apitoken = body['apitoken']
        pdserver = body['pdserver']
        wampRouter = body['wampRouter']

        changed = False
        if routerId != nexus.core.info.pdid \
            or pdserver != nexus.core.info.pdserver \
            or wampRouter != nexus.core.info.wampRouter:
            if pdserver and wampRouter:
                nexus.core.provision(routerId, pdserver, wampRouter)
            else:
                nexus.core.provision(routerId)
            changed = True

        if apitoken != nexus.core.getKey('apitoken'):
            nexus.core.saveKey(apitoken, 'apitoken')
            changed = True

        if changed:
            PDServerRequest.resetToken()
            nexus.core.jwt_valid = False

            def set_update_fetcher(session):
                session.set_update_fetcher(self.update_fetcher)

            @inlineCallbacks
            def start_polling(result):
                yield self.update_fetcher.start_polling()

            def send_response(result):
                response = dict()
                response['provisioned'] = True
                response['httpConnected'] = nexus.core.jwt_valid
                response['wampConnected'] = nexus.core.wamp_connected
                request.setHeader('Content-Type', 'application/json')
                return json.dumps(response)

            wampDeferred = nexus.core.connect(WampSession)
            wampDeferred.addCallback(set_update_fetcher)

            httpDeferred = sendStateReport()
            httpDeferred.addCallback(start_polling)

            identDeferred = sendNodeIdentity()

            dl = DeferredList([wampDeferred, httpDeferred, identDeferred],
                    consumeErrors=True)
            dl.addBoth(send_response)
            reactor.callLater(6, dl.cancel)
            return dl
        else:
            return json.dumps({'success': False,
                               'message': 'No change on the provision parameters'})
开发者ID:ParadropLabs,项目名称:Paradrop,代码行数:62,代码来源:config_api.py

示例3: run

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
 def run(self):
     jobs, self._jobs = self._jobs[:], []
     jobs_done = DeferredList(jobs)
     jobs_done.addBoth(lambda ignore: self._thread_pool.stop())
     jobs_done.addBoth(lambda ignore: reactor.stop())
     reactor.callWhenRunning(self._thread_pool.start)
     reactor.run(self._install_signal_handlers)
开发者ID:pombreda,项目名称:UnnaturalCodeFork,代码行数:9,代码来源:core.py

示例4: stop

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
    def stop(self):
        log.info("\n")
        log.info('end-of-execution-stopping-consumers')
        # Ask each of our consumers to stop. When a consumer fully stops, it
        # fires the deferred returned from its start() method. We saved all
        # those deferreds away (above, in start()) in self._consumer_d_list,
        # so now we'll use a DeferredList to wait for all of them...
        for consumer in self._consumer_list:
            consumer.stop()
        dl = DeferredList(self._consumer_d_list)

        # Once the consumers are all stopped, then close our client
        def _stop_client(result):
            if isinstance(result, Failure):
                log.error('error', result=result)
            else:
                log.info('all-consumers-stopped', client=self._client)
            self._client.close()
            return result

        dl.addBoth(_stop_client)

        # And once the client is shutdown, stop the reactor
        def _stop_reactor(result):
            reactor.stop()
            return result

        dl.addBoth(_stop_reactor)
开发者ID:gcgirish-radisys,项目名称:voltha,代码行数:30,代码来源:kafka-consumer.py

示例5: asynchroTest

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
def asynchroTest(requests, addresses):
    dl = list()
    for z in zip(requests, addresses):
        d = agent.request('POST', z[1], bodyProducer=StringProducer(z[0]))
        d.addCallback(printResource)
        dl.append(d)
    deferList = DeferredList(dl, consumeErrors=True)
    deferList.addCallback(printResource)
    deferList.addBoth(stop)
    reactor.run()
开发者ID:hult1989,项目名称:wsProj,代码行数:12,代码来源:localtest.py

示例6: assignment_stopped

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
 def assignment_stopped(_, assign_id):
     logger.debug("Assignment %s has stopped", assign_id)
     if (len(config["current_assignments"]) <= 1 and
         not self.agent.shutting_down):
         config["state"] = AgentState.ONLINE
         self.agent.reannounce(force=True)
     assignment = config["current_assignments"][assign_id]
     if "jobtype" in assignment:
         jobtype_id = assignment["jobtype"].pop("id", None)
         if jobtype_id:
             jobtype = config["jobtypes"].pop(jobtype_id, None)
             updates_deferred = DeferredList(
                 jobtype.task_update_deferreds)
             updates_deferred.addBoth(remove_assignment, assign_id)
     else:
         config["current_assignments"].pop(assign_id)
开发者ID:xlhtc007,项目名称:pyfarm-agent,代码行数:18,代码来源:assign.py

示例7: process_ack

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
    def process_ack(self, data):
        """Process an ack message, delete notifications from storage if
        needed"""
        updates = data.get("updates")
        if not updates or not isinstance(updates, list):
            return

        self.ps.metrics.increment("updates.client.ack", tags=self.base_tags)
        defers = filter(None, map(self.ack_update, updates))

        if defers:
            self.transport.pauseProducing()
            dl = DeferredList(defers)
            dl.addBoth(self.check_missed_notifications, True)
        else:
            self.check_missed_notifications(None)
开发者ID:martinthomson,项目名称:autopush,代码行数:18,代码来源:websocket.py

示例8: get

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
    def get(self):
        """HTTP Get

        Returns basic information about the version and how many clients are
        connected in a JSON object.

        """
        self._healthy = True
        self._health_checks = {
            "version": __version__,
            "clients": len(self.ap_settings.clients)
        }

        dl = DeferredList([
            self._check_table(self.ap_settings.router.table),
            self._check_table(self.ap_settings.storage.table)
        ])
        dl.addBoth(self._finish_response)
开发者ID:crodjer,项目名称:autopush,代码行数:20,代码来源:health.py

示例9: run

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
 def run(self):
     """
     Start SQL collection.
     """
     deferreds = []
     for plugin in self.plugins:
         log.debug("Running collection for plugin %s", plugin.name())
         tasks = []
         for table, task in plugin.prepareQueries(self.device).iteritems():
             dsc = DataSourceConfig(*task)
             dbapiName = dsc.connectionString.split(',', 1)[0].strip('\'"')
             executor = self._pools.setdefault(dbapiName, adbapiExecutor())
             deferred = executor.submit(dsc)
             deferred.addBoth(self.parseResult,plugin.name(),table,dbapiName)
             tasks.append(deferred)
         tdl = DeferredList(tasks)
         deferreds.append(tdl)
         tdl.addBoth(self.collectComplete, plugin)
     dl = DeferredList(deferreds)
     dl.addBoth(self.collectComplete, None)
开发者ID:alienth,项目名称:ZenPacks.community.SQLDataSource,代码行数:22,代码来源:SQLClient.py

示例10: stringReceived

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
    def stringReceived(self, string):
        """
        This is the 'main' RPC method. This will always be called when
        a request arrives and it's up to this method to parse the request and
        dispatch it further.

        @type string: str
        @param string: Request from client, just the 'string' itself, already
            stripped of the netstring stuff.

        @rtype: DeferredList
        @return: Deferred, that will fire when all methods are finished. It
            will already have all the callbacks and errbacks neccessary to
            finish and send the response.
        """

        self._logRequest(string)
        try:
            request_content = jsonrpc.decodeRequest(string)
        except jsonrpc.JSONRPCError:
            self._parseError()
            return None

        is_batch = True
        if not isinstance(request_content, list):
            request_content = [request_content]
            is_batch = False

        dl = []
        for request_dict in request_content:
            d = succeed(request_dict)
            d.addCallback(jsonrpc.verifyMethodCall)
            d.addCallback(self._callMethod)
            d.addBoth(jsonrpc.prepareMethodResponse, request_dict['id'],
                      request_dict['jsonrpc'])
            dl.append(d)

        dl = DeferredList(dl, consumeErrors=True)
        dl.addBoth(self._cbFinishRequest, is_batch)

        return dl
开发者ID:GoodDingo,项目名称:fastjsonrpc,代码行数:43,代码来源:netstringserver.py

示例11: oneBatch

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
def oneBatch(prev, ipList):
	done = 0
	deferreds = []
	for toDo in ipList:
		deferreds.append(makeRequest(toDo))
		done += 1
		if done == concurrentRequests: break
	else:
		print "\n%d requests ended in empty match" % prev
		d = getPage("%s/stats/avg" % (baseUrl, ))
		@d.addCallback
		def c2(time):
			print "Average matching time in server: %s" % time
			reactor.stop()
		return
	d = DeferredList(deferreds)
	@d.addCallback
	def c(results):
		return prev + len([x for x in results if x[1] in ("[]", "ok\n")])
	d.addErrback(log.err)
	d.addBoth(oneBatch, ipList)
开发者ID:kleopatra999,项目名称:scala-backend,代码行数:23,代码来源:many.py

示例12: rename_folder

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
    def rename_folder(self, folder, new_folder):
        """
        Renames a folder within a torrent.  This basically does a file rename
        on all of the folders children.

        :returns: A deferred which fires when the rename is complete
        :rtype: twisted.internet.defer.Deferred
        """
        log.debug("attempting to rename folder: %s to %s", folder, new_folder)
        if len(new_folder) < 1:
            log.error("Attempting to rename a folder with an invalid folder name: %s", new_folder)
            return

        new_folder = sanitize_filepath(new_folder, folder=True)

        def on_file_rename_complete(result, wait_dict, index):
            wait_dict.pop(index, None)

        wait_on_folder = {}
        self.waiting_on_folder_rename.append(wait_on_folder)
        for f in self.get_files():
            if f["path"].startswith(folder):
                # Keep track of filerenames we're waiting on
                wait_on_folder[f["index"]] = Deferred().addBoth(on_file_rename_complete, wait_on_folder, f["index"])
                new_path = f["path"].replace(folder, new_folder, 1)
                try:
                    self.handle.rename_file(f["index"], new_path)
                except TypeError:
                    self.handle.rename_file(f["index"], new_path.encode("utf-8"))

        def on_folder_rename_complete(result, torrent, folder, new_folder):
            component.get("EventManager").emit(TorrentFolderRenamedEvent(torrent.torrent_id, folder, new_folder))
            # Empty folders are removed after libtorrent folder renames
            self.remove_empty_folders(folder)
            torrent.waiting_on_folder_rename = filter(None, torrent.waiting_on_folder_rename)
            component.get("TorrentManager").save_resume_data((self.torrent_id,))

        d = DeferredList(wait_on_folder.values())
        d.addBoth(on_folder_rename_complete, self, folder, new_folder)
        return d
开发者ID:Ashod,项目名称:Deluge,代码行数:42,代码来源:torrent.py

示例13: render

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
    def render(self, request):
        """
        This is the 'main' RPC method. This will always be called when
        a request arrives and it's up to this method to parse the request and
        dispatch it further.

        @type request: t.w.s.Request
        @param request: Request from client

        @rtype: some constant :-)
        @return: NOT_DONE_YET signalizing, that there's Deferred, that will
            take care about sending the response.

        @TODO verbose mode
        """

        try:
            request_content = self._getRequestContent(request)
        except jsonrpc.JSONRPCError:
            self._parseError(request)
            return server.NOT_DONE_YET

        is_batch = True
        if not isinstance(request_content, list):
            request_content = [request_content]
            is_batch = False

        dl = []
        for request_dict in request_content:
            d = succeed(request_dict)
            d.addCallback(jsonrpc.verifyMethodCall)
            d.addCallback(self._callMethod)
            d.addBoth(jsonrpc.prepareMethodResponse, request_dict['id'],
                      request_dict['jsonrpc'])
            dl.append(d)

        dl = DeferredList(dl, consumeErrors=True)
        dl.addBoth(self._cbFinishRequest, request, is_batch)

        return server.NOT_DONE_YET
开发者ID:auxten,项目名称:fastjsonrpc,代码行数:42,代码来源:server.py

示例14: onLeave

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
    def onLeave(self, details):
        # when this router is shutting down, we disconnect all our
        # components so that they have a chance to shutdown properly
        # -- e.g. on a ctrl-C of the router.
        leaves = []
        for component in self.components.values():
            if component.session.is_connected():
                d = maybeDeferred(component.session.leave)

                def done(_):
                    self.log.info(
                        "component '{id}' disconnected",
                        id=component.id,
                    )
                    component.session.disconnect()
                d.addCallback(done)
                leaves.append(d)
        dl = DeferredList(leaves, consumeErrors=True)
        # we want our default behavior, which disconnects this
        # router-worker, effectively shutting it down .. but only
        # *after* the components got a chance to shutdown.
        dl.addBoth(lambda _: super(RouterWorkerSession, self).onLeave(details))
开发者ID:FirefighterBlu3,项目名称:crossbar,代码行数:24,代码来源:router.py

示例15: cleanUp

# 需要导入模块: from twisted.internet.defer import DeferredList [as 别名]
# 或者: from twisted.internet.defer.DeferredList import addBoth [as 别名]
    def cleanUp(self):
        """Thorough clean-up method to cancel all remaining deferreds, and send
        connection metrics in"""
        self.metrics.increment("client.socket.disconnect", tags=self.base_tags)
        elapsed = (ms_time() - self.connected_at) / 1000.0
        self.metrics.timing("client.socket.lifespan", duration=elapsed,
                            tags=self.base_tags)

        # Cleanup our client entry
        if self.uaid and self.ap_settings.clients.get(self.uaid) == self:
            del self.ap_settings.clients[self.uaid]

        # Cancel any outstanding deferreds
        for d in self._callbacks:
            d.cancel()

        # Attempt to deliver any notifications not originating from storage
        if self.direct_updates:
            defers = []
            for chid, version in self.direct_updates.items():
                d = deferToThread(
                    self.ap_settings.storage.save_notification,
                    self.uaid,
                    chid,
                    version
                )
                d.addErrback(self.log_err)
                defers.append(d)

            # Tag on the notifier once everything has been stored
            dl = DeferredList(defers)
            dl.addBoth(self._lookup_node)

        # Delete and remove remaining dicts and lists
        del self.direct_updates
        del self.updates_sent
开发者ID:crodjer,项目名称:autopush,代码行数:38,代码来源:websocket.py


注:本文中的twisted.internet.defer.DeferredList.addBoth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。