當前位置: 首頁>>代碼示例>>Python>>正文


Python reactor.crash方法代碼示例

本文整理匯總了Python中twisted.internet.reactor.crash方法的典型用法代碼示例。如果您正苦於以下問題:Python reactor.crash方法的具體用法?Python reactor.crash怎麽用?Python reactor.crash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在twisted.internet.reactor的用法示例。


在下文中一共展示了reactor.crash方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: testCrash

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def testCrash(self):
        """reactor.crash should NOT fire shutdown triggers"""
        self.counter = 0
        self.problem = 0
        self.addTrigger("before", "shutdown", self.count)
        # reactor.crash called from an "after-startup" trigger is too early
        # for the gtkreactor: gtk_mainloop is not yet running. Same is true
        # when called with reactor.callLater(0). Must be >0 seconds in the
        # future to let gtk_mainloop start first.
        self.addTimer(0.1, self.crash)
        t = self.addTimer(5, self.timeout)
        reactor.run()
        # this will fire reactor.crash, which ought to exit .run without
        # running the event triggers
        self.failUnless(self.counter == 0,
                        "reactor.crash invoked shutdown triggers, "
                        "but it isn't supposed to")
        self.failIf(self.problem, "the test timed out")
        self.removeTimer(t) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:21,代碼來源:test_internet.py

示例2: __init__

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def __init__(self, master, create, callback, items):
        Tkinter.Menu.__init__(self, master)

        cmdMenu = Tkinter.Menu(self)
        self.add_cascade(label="Actions", menu=cmdMenu)
        
        cmdMenu.add_command(label='Create', command=create)
        cmdMenu.add_separator()
        cmdMenu.add_command(label='Quit', command=reactor.crash)

        tapMenu = Tkinter.Menu(self)
        self.add_cascade(label="Applications", menu=tapMenu)

        for item in items:
            tapMenu.add_command(
                label=item, command=lambda i=item, c = callback: c(i)
            ) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:19,代碼來源:tkmktap.py

示例3: _run

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def _run(self, methodName, result):
        from twisted.internet import reactor
        timeout = self.getTimeout()
        def onTimeout(d):
            e = defer.TimeoutError("%r (%s) still running at %s secs"
                % (self, methodName, timeout))
            f = failure.Failure(e)
            # try to errback the deferred that the test returns (for no gorram
            # reason) (see issue1005 and test_errorPropagation in
            # test_deferred)
            try:
                d.errback(f)
            except defer.AlreadyCalledError:
                # if the deferred has been called already but the *back chain
                # is still unfinished, crash the reactor and report timeout
                # error ourself.
                reactor.crash()
                self._timedOut = True # see self._wait
                todo = self.getTodo()
                if todo is not None and todo.expected(f):
                    result.addExpectedFailure(self, f, todo)
                else:
                    result.addError(self, f)
        onTimeout = utils.suppressWarnings(
            onTimeout, util.suppress(category=DeprecationWarning))
        method = getattr(self, methodName)
        if inspect.isgeneratorfunction(method):
            exc = TypeError(
                '%r is a generator function and therefore will never run' % (
                    method,))
            return defer.fail(exc)
        d = defer.maybeDeferred(
            utils.runWithWarningsSuppressed, self._getSuppress(), method)
        call = reactor.callLater(timeout, onTimeout, d)
        d.addBoth(lambda x : call.active() and call.cancel() or x)
        return d 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:38,代碼來源:_asynctest.py

示例4: _makeReactorMethod

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def _makeReactorMethod(self, name):
        """
        Create a method which wraps the reactor method C{name}. The new
        method issues a deprecation warning and calls the original.
        """
        def _(*a, **kw):
            warnings.warn("reactor.%s cannot be used inside unit tests. "
                          "In the future, using %s will fail the test and may "
                          "crash or hang the test run."
                          % (name, name),
                          stacklevel=2, category=DeprecationWarning)
            return self._reactorMethods[name](*a, **kw)
        return _ 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:15,代碼來源:_asynctest.py

示例5: _deprecateReactor

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def _deprecateReactor(self, reactor):
        """
        Deprecate C{iterate}, C{crash} and C{stop} on C{reactor}. That is,
        each method is wrapped in a function that issues a deprecation
        warning, then calls the original.

        @param reactor: The Twisted reactor.
        """
        self._reactorMethods = {}
        for name in ['crash', 'iterate', 'stop']:
            self._reactorMethods[name] = getattr(reactor, name)
            setattr(reactor, name, self._makeReactorMethod(name)) 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:14,代碼來源:_asynctest.py

示例6: test_callbackReturnsNonCallingDeferred

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def test_callbackReturnsNonCallingDeferred(self):
        #hacky timeout
        # raises KeyboardInterrupt because Trial sucks
        from twisted.internet import reactor
        call = reactor.callLater(2, reactor.crash)
        result = self.runTest('test_calledButNeverCallback')
        if call.active():
            call.cancel()
        self.assertFalse(result.wasSuccessful())
        self._wasTimeout(result.errors[0][1])


# The test loader erroneously attempts to run this: 
開發者ID:proxysh,項目名稱:Safejumper-for-Desktop,代碼行數:15,代碼來源:test_deferred.py

示例7: test_callbackReturnsNonCallingDeferred

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def test_callbackReturnsNonCallingDeferred(self):
        #hacky timeout
        # raises KeyboardInterrupt because Trial sucks
        from twisted.internet import reactor
        call = reactor.callLater(2, reactor.crash)
        result = self.runTest('test_calledButNeverCallback')
        if call.active():
            call.cancel()
        self.failIf(result.wasSuccessful())
        self._wasTimeout(result.errors[0][1]) 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:12,代碼來源:test_deferred.py

示例8: _run

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def _run(self, methodName, result):
        from twisted.internet import reactor
        timeout = self.getTimeout()
        def onTimeout(d):
            e = defer.TimeoutError("%r (%s) still running at %s secs"
                % (self, methodName, timeout))
            f = failure.Failure(e)
            # try to errback the deferred that the test returns (for no gorram
            # reason) (see issue1005 and test_errorPropagation in
            # test_deferred)
            try:
                d.errback(f)
            except defer.AlreadyCalledError:
                # if the deferred has been called already but the *back chain
                # is still unfinished, crash the reactor and report timeout
                # error ourself.
                reactor.crash()
                self._timedOut = True # see self._wait
                todo = self.getTodo()
                if todo is not None and todo.expected(f):
                    result.addExpectedFailure(self, f, todo)
                else:
                    result.addError(self, f)
        onTimeout = utils.suppressWarnings(
            onTimeout, util.suppress(category=DeprecationWarning))
        method = getattr(self, methodName)
        d = defer.maybeDeferred(utils.runWithWarningsSuppressed,
                                self.getSuppress(), method)
        call = reactor.callLater(timeout, onTimeout, d)
        d.addBoth(lambda x : call.active() and call.cancel() or x)
        return d 
開發者ID:kuri65536,項目名稱:python-for-android,代碼行數:33,代碼來源:unittest.py

示例9: test_callbackReturnsNonCallingDeferred

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def test_callbackReturnsNonCallingDeferred(self):
        #hacky timeout
        # raises KeyboardInterrupt because Trial sucks
        from twisted.internet import reactor
        call = reactor.callLater(2, reactor.crash)
        result = self.runTest('test_calledButNeverCallback')
        if call.active():
            call.cancel()
        self.failIf(result.wasSuccessful())
        self.failUnlessEqual(len(result.errors), 1)
        self._wasTimeout(result.errors[0][1]) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:13,代碼來源:test_deferred.py

示例10: _run

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def _run(self, methodName, result):
        from twisted.internet import reactor
        timeout = self.getTimeout()
        def onTimeout(d):
            e = defer.TimeoutError("%r (%s) still running at %s secs"
                % (self, methodName, timeout))
            f = failure.Failure(e)
            # try to errback the deferred that the test returns (for no gorram
            # reason) (see issue1005 and test_errorPropagation in test_deferred)
            try:
                d.errback(f)
            except defer.AlreadyCalledError:
                # if the deferred has been called already but the *back chain is
                # still unfinished, crash the reactor and report timeout error
                # ourself.
                reactor.crash()
                self._timedOut = True # see self._wait
                todo = self.getTodo()
                if todo is not None and todo.expected(f):
                    result.addExpectedFailure(self, f, todo)
                else:
                    result.addError(self, f)
        if self._shared:
            test = self.__class__._testCaseInstance
        else:
            test = self
        method = getattr(test, methodName)
        d = defer.maybeDeferred(utils.runWithWarningsSuppressed,
                                self.getSuppress(), method)
        call = reactor.callLater(timeout, onTimeout, d)
        d.addBoth(lambda x : call.active() and call.cancel() or x)
        return d 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:34,代碼來源:unittest.py

示例11: writeSomething

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def writeSomething(self):
        if self.disconnected:
            if not self.finished:
                self.fail()
            else:
                reactor.crash()
        if not self.disconnected:
            self.transport.write('foo')
            reactor.callLater(1, self.writeSomething) 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:11,代碼來源:test_policies.py

示例12: crash

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def crash(self):
        reactor.crash() 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:4,代碼來源:test_internet.py

示例13: testIterate

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def testIterate(self):
        """Test that reactor.iterate(0) doesn't block"""
        start = time.time()
        # twisted timers are distinct from the underlying event loop's
        # timers, so this fail-safe probably won't keep a failure from
        # hanging the test
        t = reactor.callLater(10, self.crash)
        reactor.iterate(0) # shouldn't block
        stop = time.time()
        elapsed = stop - start
        #print "elapsed", elapsed
        self.failUnless(elapsed < 8)
        t.cancel() 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:15,代碼來源:test_internet.py

示例14: destroy

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def destroy(self):
        reactor.crash()
        Tkinter.Frame.destroy(self)


#
# This class was written based on code from Drew "drewp" Pertulla
# (<drewp (at) bigasterisk (dot) com>) - without his help, tkmktap
# would be an ugly POS.
# 
開發者ID:kenorb-contrib,項目名稱:BitTorrent,代碼行數:12,代碼來源:tkmktap.py

示例15: test

# 需要導入模塊: from twisted.internet import reactor [as 別名]
# 或者: from twisted.internet.reactor import crash [as 別名]
def test(arguments):
        arguments['test'] = True
        reactor.crash() 
開發者ID:hgascon,項目名稱:pulsar,代碼行數:5,代碼來源:Signal.py


注:本文中的twisted.internet.reactor.crash方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。