How to use the twisted.internet.defer.maybeDeferred function in Twisted

To help you get started, we’ve selected a few Twisted examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Times-0 / Timeline / Timeline / Utils / Events.py View on Github external
def call(self, e, *a, **kw):
        defer = Deferred()
        if not e in self.events:
            return defer

        EventDetails = {'e' : e, 'a' : a, 'kw' : kw}
        return maybeDeferred(self.callback, self.events[e], EventDetails)
github richardingham / octopus / octopus / sequence / util.py View on Github external
def resume (self):
		if self.state is not State.PAUSED:
			raise NotPaused

		self.state = State.RUNNING
		d = defer.maybeDeferred(self._resume)

		try:
			onResume, self._onResume = self._onResume, None
			onResume()
		except (AttributeError, TypeError):
			pass

		return d
github foundit / Piped / contrib / zookeeper / piped_zookeeper / providers.py View on Github external
if self.running:
            service.Service.stopService(self)

            self._on_event('stopping')

            # if we're currently trying to reconnect, stop trying
            if self._currently_reconnecting:
                self._currently_reconnecting.cancel()

            # if we're currently trying to connect, stop trying
            if self._currently_connecting:
                self._currently_connecting.cancel()

            # if we have a client, try to close it, as it might be functional
            if self._current_client:
                defer.maybeDeferred(self._current_client.close).addErrback(lambda _: None)
                self._current_client = None

            self.on_disconnected(failure.Failure(DisconnectException('stopping service')))
github ClusterHQ / flocker / flocker / provision / _libcloud.py View on Github external
action = start_action(
            action_type=u"flocker:provision:libcloud:create_nodes",
            instance_count=len(names),
            distribution=distribution,
            size=size,
            metadata=metadata,
        )
        with action.context():
            results = []
            for name in names:
                Message.log(
                    message_type=u"flocker:provision:libcloud:creating_node",
                    node_name=name,
                )
                d = maybeDeferred(
                    self._driver.create_node,
                    name=name,
                    image=get_image(self._driver, image_name),
                    size=get_size(self._driver, size),
                    ex_keyname=self._keyname,
                    ex_metadata=metadata,
                    **create_node_arguments
                )
                d = DeferredContext(d)
                d.addCallbacks(
                    lambda node: self._wait_until_running(reactor, node),
                    errback=handle_create_error,
                    errbackArgs=(name,),
                )
                d.addCallback(make_node)
                results.append(d.result)
github nlloyd / SubliminalCollaborator / libs / twisted / mail / pop3.py View on Github external
        @param i: The number of the message to operate on.  This is a base-ten
        string representation starting at 1.

        @return: A Deferred which fires with a two-tuple of an integer and a
        file-like object.
        """
        try:
            msg = int(i) - 1
            if msg < 0:
                raise ValueError()
        except ValueError:
            self.failResponse("Bad message number argument")
            return defer.succeed(None)

        sizeDeferred = defer.maybeDeferred(self.mbox.listMessages, msg)
        def cbMessageSize(size):
            if not size:
                return defer.fail(_POP3MessageDeleted())
            fileDeferred = defer.maybeDeferred(self.mbox.getMessage, msg)
            fileDeferred.addCallback(lambda fObj: (size, fObj))
            return fileDeferred

        def ebMessageSomething(err):
            errcls = err.check(_POP3MessageDeleted, ValueError, IndexError)
            if errcls is _POP3MessageDeleted:
                self.failResponse("message deleted")
            elif errcls in (ValueError, IndexError):
                if errcls is IndexError:
                    # XXX TODO See above comment regarding IndexError.
                    warnings.warn(
                        "twisted.mail.pop3.IMailbox.listMessages may not "
github scanlime / navi-misc / cia / tools / graph_foo.py View on Github external
def connectionMade(self):
        defer.maybeDeferred(self.stdinCallback, self.transport).addCallback(
            self._finishedWriting).addErrback(self.resultDeferred.errback)
github twisted / imaginary / imaginary / wiring / ssh.py View on Github external
def stopService(self):
        L = []
        if self.port is not None:
            L.append(defer.maybeDeferred(self.port.stopListening))
            self.port = None
        return defer.DeferredList(L)
github quattor / aquilon / 1.1 / src / lib / python2.5 / aquilon / server / broker.py View on Github external
def show_service(self, arguments, request_path, user):
        d = defer.maybeDeferred(self.azbroker.check, None, user,
                "show", request_path)
        d = d.addCallback(self.dbbroker.show_service, session=True,
                user=user, **arguments)
        return d
github buildbot / buildbot / master / buildbot / process / users / manager.py View on Github external
def reconfigServiceWithBuildbotConfig(self, new_config):
        # this is easy - kick out all of the old managers, and add the
        # new ones.

        # pylint: disable=cell-var-from-loop
        for mgr in list(self):
            yield defer.maybeDeferred(mgr.disownServiceParent)

        for mgr in new_config.user_managers:
            yield mgr.setServiceParent(self)

        # reconfig any newly-added change sources, as well as existing
        yield super().reconfigServiceWithBuildbotConfig(new_config)
github quattor / aquilon / 1.1.1 / src / lib / python2.5 / aquilon / server / broker.py View on Github external
def show_location_type(self, arguments, request_path, user):
        d = defer.maybeDeferred(self.azbroker.check, None, user,
                "show", request_path)
        d = d.addCallback(self.dbbroker.show_location_type, session=True,
                user=user, **arguments)
        return d