def wrapper(*args, **kwargs):
        nextValue = None
        result = None

        gen = f(*args, **kwargs)
        while True:
            _t = time.time()
            if nextValue:
                result = gen.send(nextValue)
            else:
                result = gen.next()

            _t = time.time() - _t
            # log calls slower than 1 second
            if _t > 1:
                logger.critical(
                    "Slow generator function iteration took %f seconds on %s line %d %s(%s) returned %r",
                    _t,
                    gen.gi_code.co_filename,
                    gen.gi_frame.f_lineno,
                    f.func_name,
                    formatargs(args, kwargs),
                    result
                )
            nextValue = yield result
예제 #2
0
파일: tests.py 프로젝트: nvbn/evilshortgen
 def test_decorator(self):
     @shortgen
     def test():
         a << sum([1, 2, 3])
         self.assertEqual(a, 5)
         b = 1
         b << 2
         self.assertEqual(b, 7)
         c, d << sum([
             1, 2,
         ])
         self.assertEqual(c, 8)
         self.assertEqual(d, 9)
     gen = test()
     self.assertEqual(6, gen.send(None))
     self.assertEqual(2, gen.send(5))
     self.assertEqual(3, gen.send(7))
     with self.assertRaises(StopIteration):
         gen.send((8, 9))
예제 #3
0
파일: tests.py 프로젝트: nvbn/evilshortgen
    def test_decorator(self):
        @shortgen
        def test():
            a << sum([1, 2, 3])
            self.assertEqual(a, 5)
            b = 1
            b << 2
            self.assertEqual(b, 7)
            c, d << sum([
                1,
                2,
            ])
            self.assertEqual(c, 8)
            self.assertEqual(d, 9)

        gen = test()
        self.assertEqual(6, gen.send(None))
        self.assertEqual(2, gen.send(5))
        self.assertEqual(3, gen.send(7))
        with self.assertRaises(StopIteration):
            gen.send((8, 9))
예제 #4
0
def try_testing(io_loop):  
    #logging.info("test_count: %s, test_remain: %s", TCPClient.test_count, TCPClient.test_remain)  
    if TCPClient.test_start and TCPClient.test_count >= TCPClient.max_connected and TCPClient.test_remain > 0:  
        TCPClient.test_start = False  
  
    if not TCPClient.test_start:  
        TCPClient.test_count = 0  
        TCPClient.test_start = True  
  
        gen = None  
        if TCPClient.test_remain >= TCPClient.max_connected:  
            gen = start_test(io_loop, TCPClient.max_connected)  
        elif TCPClient.test_remain > 0:  
            gen = start_test(io_loop, TCPClient.test_remain)  
  
        if gen:  
            with stack_context.ExceptionStackContext(_handle_exception):  
                c = gen.next()  
                while True:  
                    c = gen.send(c)  
예제 #5
0
    def wrapper(*args, **kwargs):
        nextValue = None
        result = None

        gen = f(*args, **kwargs)
        while True:
            _t = time.time()
            if nextValue:
                result = gen.send(nextValue)
            else:
                result = gen.next()

            _t = time.time() - _t
            # log calls slower than 1 second
            if _t > 1:
                logger.critical(
                    "Slow generator function iteration took %f seconds on %s line %d %s(%s) returned %r",
                    _t, gen.gi_code.co_filename, gen.gi_frame.f_lineno,
                    f.func_name, formatargs(args, kwargs), result)
            nextValue = yield result