def external_coro():
     tran = transaction.begin(loop=event_loop)
     # in py3.5
     # async with tran:
     #     a = A()
     a = A()
     yield from tran.end()
 def external_coro():
     tran = transaction.begin(loop=event_loop)
     # in py3.5
     # async with tran:
     #     a = A()
     a = A()
     yield from tran.end()
 def external_coro():
     nonlocal tasks_ids
     task = asyncio.Task.current_task(loop=event_loop)
     tasks_ids.add(id(task))
     tran = transaction.begin(loop=event_loop)
     # in py3.5
     # async with tran:
     #     non_coro_func()
     non_coro_func()
 def external_coro():
     nonlocal tasks_ids
     task = asyncio.Task.current_task(loop=event_loop)
     tasks_ids.add(id(task))
     tran = transaction.begin(loop=event_loop)
     # in py3.5
     # async with tran:
     #     non_coro_func()
     non_coro_func()
Example #5
0
def test_calling_from_non_task():

    results = []

    @asyncio.coroutine
    def stashed_coro():
        nonlocal results
        results.append('called stashed_coro')

    def non_coro_func():
        tran = transaction.get()
        c = stashed_coro()
        tran.add(c)

    # create a new event loop because i get a closed one with
    # get_event_loop(), probably a conflict with pytest-asyncio
    loop = asyncio.new_event_loop()
    tran = transaction.begin(loop=loop)
    non_coro_func()
    assert len(results) == 0
    loop.run_until_complete(tran.end())
    assert len(results) == 1
def test_calling_from_non_task():

    tasks_ids = set()
    results = []

    @asyncio.coroutine
    def stashed_coro():
        nonlocal results
        results.append('called stashed_coro')

    def non_coro_func():
        tran = transaction.get()
        c = stashed_coro()
        tran.add(c)

    # create a new event loop because i get a closed one with
    # get_event_loop(), probably a conflict with pytest-asyncio
    loop = asyncio.new_event_loop()
    tran = transaction.begin(loop=loop)
    non_coro_func()
    assert len(results) == 0
    loop.run_until_complete(tran.end())
    assert len(results) == 1
 def external_coro():
     nonlocal master_trans
     trans = transaction.begin(loop=event_loop)
     master_trans = trans
     sync()
     yield from trans.end()
 def external_coro():
     t = transaction.begin()
     c1, c2 = coro1(), coro2()
     r = yield from asyncio.gather(*t.add(c1, c2), loop=event_loop)
     yield from t.end()
     return r
 def external_coro():
     nonlocal outer_trans
     t = transaction.begin(loop=event_loop)
     outer_trans = t
     sync_func()
     yield from transaction.end(loop=event_loop)