예제 #1
0
 def get_cls_and_args(cls, number):
     print('get_cls_and_args')
     assert cls.get_cls_ac() is cls
     assert (yield cls.get_cls_ac.asynq()) is cls
     assert cls.get_cls().value() is cls
     assert (yield cls.get_cls()) is cls
     result((cls, number)); return
예제 #2
0
 def capybara():
     val1 = 0
     try:
         val1 += yield async_fn.asynq(1)
     except OverflowError:
         val1 += yield async_fn.asynq(4)
     result(val1)
예제 #3
0
    def foo(num_yield):
        if num_yield == 0:
            result(0)
            return

        yield ExternalCacheBatchItem(mc._batch, "get", "test")
        yield foo.asynq(num_yield - 1)
예제 #4
0
파일: test_tools.py 프로젝트: vic4key/asynq
def recursive_call_with_dirty():
    global i
    if i > 0:
        result(i); return
    i += 1
    recursive_call_with_dirty.dirty()
    yield recursive_call_with_dirty.asynq()
예제 #5
0
def _push_async(channel, value):
    yield None
    while True:
        if channel.push(value, False) is future_true:
            result(future_true)
            return
        yield None
예제 #6
0
 def incr():
     global counter
     counter += 1
     print("Counter: %i" % counter)
     result(counter)
     return
     yield
예제 #7
0
        def capybara(oid):
            second_oid = yield cached_fn.asynq(oid)
            new_oid = yield async_fn.asynq(second_oid)

            def process():
                return new_oid - 2

            result(process())
예제 #8
0
 def async_fn_with_yield(should_yield):
     with Ctx():
         if should_yield:
             ret = yield ExternalCacheBatchItem(mc._batch, 'get', 'test')
         else:
             ret = 0
     result(ret)
     return
예제 #9
0
 def capybara(qid, include_deleted):
     if include_deleted:
         value = yield PropertyObject.load.asynq(qid,
                                                 include_deleted=False)
     else:
         value = yield PropertyObject.load.asynq(qid,
                                                 include_deleted=True)
     result(value)
예제 #10
0
def _pull_async(channel):
    yield None
    while True:
        item = channel.pull(False)
        if item is not future_empty:
            result(item)
            return
        yield None
예제 #11
0
 def sum_async(i, dump_progress=False):
     if i == 0:
         result(0)
         return
     if dump_progress and i % 100 == 0:
         print('... in sum_async(%s)' % i)
     result(i + (yield sum_async.asynq(i - 1, dump_progress)))
     return
예제 #12
0
파일: tests.py 프로젝트: tausif3/pyanalyze
 def _call_pure(self, args, kwargs):
     try:
         result(self.cache[args])
         return
     except KeyError:
         value = yield self.async_fn(*args)
         self.cache[args] = value
         result(value)
         return
예제 #13
0
 def throw(raise_in_pause, raise_in_resume):
     with SimpleContext():
         with ContextThatRaises(raise_in_pause, raise_in_resume):
             with SimpleContext():
                 # we need this to have a real dependency on an async task, otherwise
                 # it executes the whole function inline and the real problem is never tested
                 val = yield dependency.asynq()
     result(val)
     return
예제 #14
0
        def capybara(qids, t):
            @asynq()
            def filter_fn(qid):
                result(
                    (yield PropertyObject(qid).get_prop_with_get.asynq()) < t)

            qids = yield afilter.asynq(filter_fn, qids)
            system_a2a_ret = yield tuple(async_fn.asynq(qid) for qid in qids)
            result(system_a2a_ret)
예제 #15
0
 def throw(expected_counter, must_throw):
     global counter
     print("  In throw, counter=%i (expected %i), must_throw=%s" %
           (counter, expected_counter, str(must_throw)))
     assert expected_counter == counter
     if must_throw:
         raise RuntimeError
     counter += 1
     result(counter)
     return
예제 #16
0
 def wrapped(*args):
     key = key_prefix + ':' + ':'.join(map(str, args))
     value = yield self.get.asynq(key)
     if value is MISS:
         # possible enhancement: make it possible for the inner function to be async
         value = fn(*args)
         # there is a race condition here since somebody else could have set the key
         # while we were computing the value, but don't worry about that for now
         yield self.set.asynq(key, value)
     result(value); return
예제 #17
0
 def wrapped(*args):
     key = key_prefix + ':' + ':'.join(map(str, args))
     value = yield self.get.asynq(key)
     if value is MISS:
         # possible enhancement: make it possible for the inner function to be async
         value = fn(*args)
         # there is a race condition here since somebody else could have set the key
         # while we were computing the value, but don't worry about that for now
         yield self.set.asynq(key, value)
     result(value)
     return
예제 #18
0
 def add_twice(a, b):
     global change_amount
     global expected_change_amount_base
     assert_eq(expected_change_amount_base, change_amount)
     with AsyncAddChanger(1):
         assert_eq(expected_change_amount_base + 1, change_amount)
         z = yield async_add(a, b)
         assert_eq(expected_change_amount_base + 1, change_amount)
         with AsyncAddChanger(1):
             q = yield async_add(a, b)
             assert_eq(expected_change_amount_base + 2, change_amount)
         assert_eq(expected_change_amount_base + 1, change_amount)
     assert_eq(expected_change_amount_base + 0, change_amount)
     result((yield async_add(z, q)))
     return
예제 #19
0
 def test_async():
     global counter
     try:
         print('In try block.')
         yield incr()
         result((yield incr()))  # ; return
         assert False, "Must not reach this point!"
     except BaseException as e:
         print('In except block, e = ' + repr(e))
         assert sync_incr() == 3
         if isinstance(e, GeneratorExit):
             raise
         assert False, "Must not reach this point!"
     finally:
         print('In finally block.')
         assert sync_incr() == 4
예제 #20
0
 def method(self, number):
     assert type(self) is MyClass
     cls, one = self.get_cls_and_args(number)
     assert cls is MyClass
     assert one == number
     cls, one = yield self.get_cls_and_args.asynq(number)
     assert cls is MyClass
     assert one == number
     one = yield self.static(number)
     assert one == number
     one = yield self.static_ac.asynq(number)
     assert one == number
     cls, proxied = yield self.async_proxy_classmethod.asynq(number)
     assert cls is MyClass
     assert proxied == number
     result(self); return
예제 #21
0
def async_scoped_value_helper(inner_val):
    @asynq()
    def nested():
        assert_eq(v.get(), inner_val)
        yield DebugBatchItem()
        with v.override('c'):
            yield DebugBatchItem()  # just so other function gets scheduled
            assert_eq(v.get(), 'c')
            yield DebugBatchItem()

    assert_eq(v.get(), 'a')
    yield DebugBatchItem()
    with v.override(inner_val):
        yield DebugBatchItem()
        assert_eq(v.get(), inner_val)
        result((yield nested.asynq()))
        return
예제 #22
0
파일: tests.py 프로젝트: tausif3/pyanalyze
 def is_prop_with_is(self):
     result((yield cached_fn.asynq(self.poid)))
     return
예제 #23
0
 def func(depth):
     if depth == 0:
         result((yield ExternalCacheBatchItem(mc._batch, 'get', 'test')))
         return
     time.sleep(float(sleep_time) / SECOND)
     yield func.asynq(depth - 1), func.asynq(depth - 1)
예제 #24
0
 def return_three_and_five(self):
     result((yield (self.return_three.asynq(), self.return_five.asynq())))
     return
예제 #25
0
파일: tests.py 프로젝트: tausif3/pyanalyze
def async_fn(oid):
    result((yield cached_fn.asynq(oid)))
    return
예제 #26
0
파일: tests.py 프로젝트: tausif3/pyanalyze
 def get_async(self):
     yield async_fn.asynq(1)
     result(2)
     return
예제 #27
0
파일: tests.py 프로젝트: tausif3/pyanalyze
def autogenerated(aid):
    result((yield async_fn.asynq(aid)))
    return
예제 #28
0
파일: tests.py 프로젝트: tausif3/pyanalyze
 def get_prop_with_get(self):
     result((yield cached_fn.asynq(self.poid)))
     return
예제 #29
0
파일: tests.py 프로젝트: tausif3/pyanalyze
 def async_classmethod(cls, poid):
     result((yield cls(poid).get_prop_with_get.asynq()))
     return
예제 #30
0
파일: tests.py 프로젝트: tausif3/pyanalyze
 def async_method(self):
     result((yield cached_fn.asynq(self.poid)))
     return
예제 #31
0
파일: tests.py 프로젝트: tausif3/pyanalyze
 def load(cls, poid, include_deleted=False):
     result((yield cls(poid).get_prop_with_get.asynq()))
     return