コード例 #1
0
 def test5(self):
     try:
         print timeout_yield(exc())
         self.assert_(False, "should've raised an exception")
     except:
         pass
     like_yield(wait(1))
コード例 #2
0
 def test5(self):
     try:
         print timeout_yield(exc())
         self.assert_(False, "should've raised an exception")
     except:
         pass
     like_yield(wait(1))
コード例 #3
0
 def test0(self):
     self.assert_(like_yield(f()) == 5, "should have returned 5.")
     self.assert_(like_yield(g(1)) == 6, "should have returned 6.")
     try:
         like_yield(exc())
         self.assert_(False, "like_yield should've raised exception.")
     except Exception, e:
         pass
コード例 #4
0
 def test0(self):
     self.assert_(like_yield(f()) == 5, "should have returned 5.")
     self.assert_(like_yield(g(1)) == 6, "should have returned 6.")
     try:
         like_yield(exc())
         self.assert_(False, "like_yield should've raised exception.")
     except Exception, e:
         pass
コード例 #5
0
    def test4(self):
        try:
            print timeout_yield(g(1), timeout=.5)
            self.assert_(False, "should've timed out.")
        except TimeoutError:
            pass

        like_yield(wait(1))
コード例 #6
0
    def test4(self):
        try:
            print timeout_yield(g(1), timeout=.5)
            self.assert_(False, "should've timed out." )
        except TimeoutError:
            pass

        like_yield(wait(1)) 
コード例 #7
0
    def _genWoosh(self):

        x = like_yield(getThing())

        self.assertEquals(x, "hi")

        try:
            like_yield(getOwie())
        except ZeroDivisionError, e:
            self.assertEquals(str(e), 'OMG')
コード例 #8
0
    def _genWoosh(self):

        x = like_yield(getThing())

        self.assertEquals(x, "hi")

        try:
            like_yield(getOwie())
        except ZeroDivisionError, e:
            self.assertEquals(str(e), 'OMG')
コード例 #9
0
ファイル: log.py プロジェクト: amitgardharia/BitTorrent-5.0.9
 def test_rate_limited_logger():
     injectLogger(verbose = True)
     log = RateLimitedLogger(logging.getLogger("myapp"), 1,1)
     log.info( "should be printed." )
     log.info( "should not be printed" )  # but should log "discard" message.
     log.info( "also should not be printed" )  # should not logging of discard message.
     df = Deferred()
     reactor.callLater(3, df.callback, True)
     like_yield(df)
     log.info( "should also be printed" )
     reactor.stop()
コード例 #10
0
 def test_rate_limited_logger():
     injectLogger(verbose = True)
     log = RateLimitedLogger(logging.getLogger("myapp"), 1,1)
     log.info( "should be printed." )
     log.info( "should not be printed" )  # but should log "discard" message.
     log.info( "also should not be printed" )  # should not logging of discard message.
     df = Deferred()
     reactor.callLater(3, df.callback, True)
     like_yield(df)
     log.info( "should also be printed" )
     reactor.stop()
コード例 #11
0
ファイル: greenlet_coro.py プロジェクト: galaxy001/libtorrent
def init_yield(clss, *args, **kwargs):
    """Instantiate an object of type clss and then call its asynchronous initializer
       (__dfinit__). The __dfinit__ returns a Deferred.  When the deferred's callback
       is called execution resumes at init_yield and the fully initialized object is
       returned."""
    kwargs['__magic_init_yield'] = True
    obj = clss(*args, **kwargs)  # synchronous initialization.
    like_yield(obj.__dfinit__())  # asynchronous initialization.
    # How it works: async_init returns a deferred.  like_yield
    # installs callbacks in the deferred to the greenlet's switch.
    # When the deferred completes, it calls the greenlet's switch
    # causing execution to resume here.
    return obj
コード例 #12
0
def init_yield(clss, *args, **kwargs):
    """Instantiate an object of type clss and then call its asynchronous initializer
       (__dfinit__). The __dfinit__ returns a Deferred.  When the deferred's callback
       is called execution resumes at init_yield and the fully initialized object is
       returned."""
    kwargs['__magic_init_yield'] = True
    obj = clss(*args, **kwargs)       # synchronous initialization.
    like_yield(obj.__dfinit__())      # asynchronous initialization.
         # How it works: async_init returns a deferred.  like_yield
         # installs callbacks in the deferred to the greenlet's switch.
         # When the deferred completes, it calls the greenlet's switch
         # causing execution to resume here.
    return obj
コード例 #13
0
ファイル: test_upnp.py プロジェクト: galaxysd/BitTorrent
def run_tests(internal_port):
    list = like_yield(nattraverser.list_ports())
    print_list(list)

    df = nattraverser.register_port(internal_port, internal_port, "TCP")
    external_port = like_yield(df)
    print "Mapped:", external_port

    list = like_yield(nattraverser.list_ports())
    print_list(list)

    # synchronous
    nattraverser.unregister_port(external_port, "TCP")
    
    list = like_yield(nattraverser.list_ports())
    print_list(list)
コード例 #14
0
def timeout_yield(orig_df, timeout = None ):
    """like_yield with a timeout.  Pased timeout is
       in seconds.  If timeout is None then uses
       the default default_yield_timeout.  If the function f
       eventually completes (i.e., its deferred gets called) after
       having already timed out then the result is tossed.

       timeout is set to None rather than default_yield_timeout so that
       the default can be changed after import timeout_yield
       by changing default_yield_timeout.

       WARNING: It is left to the caller to free up any state that might
       be held by the hung deferred.
       """
    assert isinstance(orig_df, defer.Deferred)
    df = defer.Deferred()
    if timeout is None:
        timeout = default_yield_timeout
    t = reactor.callLater(timeout, defer.timeout, df)
    def good(r):
        if t.active():
            df.callback(r)
    def bad(r):
        if t.active():
            df.errback(r)
    orig_df.addCallbacks(good, bad)
    try:
        r = like_yield(df)
    finally:
        if t.active():
            t.cancel()
    return r
コード例 #15
0
def run_tests(internal_port):
    list = like_yield(nattraverser.list_ports())
    print_list(list)

    df = nattraverser.register_port(internal_port, internal_port, "TCP")
    external_port = like_yield(df)
    print "Mapped:", external_port

    list = like_yield(nattraverser.list_ports())
    print_list(list)

    # synchronous
    nattraverser.unregister_port(external_port, "TCP")

    list = like_yield(nattraverser.list_ports())
    print_list(list)
コード例 #16
0
ファイル: greenlet_coro.py プロジェクト: galaxy001/libtorrent
def timeout_yield(orig_df, timeout=None):
    """like_yield with a timeout.  Pased timeout is
       in seconds.  If timeout is None then uses
       the default default_yield_timeout.  If the function f
       eventually completes (i.e., its deferred gets called) after
       having already timed out then the result is tossed.

       timeout is set to None rather than default_yield_timeout so that
       the default can be changed after import timeout_yield
       by changing default_yield_timeout.

       WARNING: It is left to the caller to free up any state that might
       be held by the hung deferred.
       """
    assert isinstance(orig_df, defer.Deferred)
    df = defer.Deferred()
    if timeout is None:
        timeout = default_yield_timeout
    t = reactor.callLater(timeout, defer.timeout, df)

    def good(r):
        if t.active():
            df.callback(r)

    def bad(r):
        if t.active():
            df.errback(r)

    orig_df.addCallbacks(good, bad)
    try:
        r = like_yield(df)
    finally:
        if t.active():
            t.cancel()
    return r
コード例 #17
0
ファイル: load_test.py プロジェクト: xiaoliukai/Helix
def main(proxy):
    global logiter
    global all_lines
    global to_remove
    for url in logiter:
        try:
            peer_id = get_param(url, "peer_id")
            if peer_id:
                peer_id = id_map.setdefault(peer_id, make_id())
                url = replace_param(url, "peer_id", peer_id)
            url = replace_param(url, "ip", "127.0.0.1")
            url = replace_param(url, "port", "6881")

            path = '/' + url.split('/', 3)[3]
            sys.stdout.write('.')
            df = proxy.callRemote(path)
            r = like_yield(df)
            r = bdecode(r)
            er = r.get('failure reason')
            if er:
                raise Exception(er)
        except Exception, e:
            print "Error", e.__class__, e, url
            to_remove.add(line)
            pass
コード例 #18
0
ファイル: load_test.py プロジェクト: dot-Sean/Helix
def main(proxy):
    global logiter
    global all_lines
    global to_remove
    for url in logiter:
        try:
            peer_id = get_param(url, "peer_id")
            if peer_id:
                peer_id = id_map.setdefault(peer_id, make_id())
                url = replace_param(url, "peer_id", peer_id)
            url = replace_param(url, "ip", "127.0.0.1")
            url = replace_param(url, "port", "6881")

            path = '/' + url.split('/', 3)[3]
            sys.stdout.write('.')
            df = proxy.callRemote(path)
            r = like_yield(df)
            r = bdecode(r)
            er = r.get('failure reason')
            if er:
                raise Exception(er)
        except Exception, e:
            print "Error", e.__class__, e, url
            to_remove.add(line)
            pass
コード例 #19
0
 def _genFailure():
     x = defer.fail(TerminalException("Handled Terminal Failure"))
     try:
         like_yield(x)
     except TerminalException:
         pass
コード例 #20
0
 def _genDeferred():
     like_yield(getThing())
コード例 #21
0
 def _genError():
     like_yield(getThing())
     1/0
コード例 #22
0
 def test2(self):
     self.assert_(timeout_yield(f(), timeout=1) == 5,
                  "with specified timeout should still return 5" )
     like_yield(wait(1))
コード例 #23
0
 def _loop():
     for x in range(5000):
         # Test with yielding a deferred
         like_yield(defer.succeed(1))
     return 0
コード例 #24
0
 def _genFailure():
     x = defer.fail(TerminalException("Handled Terminal Failure"))
     try:
         like_yield(x)
     except TerminalException:
         pass
コード例 #25
0
def g(t):
    sys.stdout.flush()
    like_yield(wait(t))
    return 6
コード例 #26
0
 def test3(self):
     self.assert_(timeout_yield(g(.1), timeout=.5) == 6, "should return 6.")
     like_yield(wait(1))
コード例 #27
0
 def test2(self):
     self.assert_(
         timeout_yield(f(), timeout=1) == 5,
         "with specified timeout should still return 5")
     like_yield(wait(1))
コード例 #28
0
 def _genFailure():
     try:
         like_yield(d)
     except TerminalException:
         pass
コード例 #29
0
 def test1(self):
     self.assert_(timeout_yield(f()) == 5, "should return 5" )
     like_yield(wait(1))
コード例 #30
0
def g(t):
    sys.stdout.flush()
    like_yield(wait(t))
    return 6
コード例 #31
0
 def _genError():
     like_yield(getThing())
     1 / 0
コード例 #32
0
 def _genFailure():
     try:
         like_yield(d)
     except TerminalException:
         pass
コード例 #33
0
 def _loop():
     for x in range(5000):
         # Test with yielding a deferred
         like_yield(defer.succeed(1))
     return 0
コード例 #34
0
 def _genDeferred():
     like_yield(getThing())
コード例 #35
0
 def test1(self):
     self.assert_(timeout_yield(f()) == 5, "should return 5")
     like_yield(wait(1))
コード例 #36
0
 def test3(self):
     self.assert_( timeout_yield(g(.1), timeout=.5) == 6,
                   "should return 6." )
     like_yield(wait(1))