# Path: falsy/netboy/curl_loop.py
# async def curl_loop():
#     while True:
#         await aio.sleep(0)
#         CurlLoop.perform()


import asyncio as aio
import json
import uvloop
from contextlib import suppress
from falsy.netboy.curl_loop import curl_loop




def exception_handler(context):
    print('context:', context)


def run(coro, loop=None):
    async def main_task():
        pycurl_task = aio.ensure_future(curl_loop())
        try:
            r = await coro
        finally:
            pycurl_task.cancel()
            with suppress(aio.CancelledError):
                await pycurl_task
        return r, pycurl_task

    if loop is None:
        loop = uvloop.new_event_loop()
        # loop = aio.get_event_loop()
    aio.set_event_loop(loop)
    loop.set_exception_handler(exception_handler)

# Path: falsy/netboy/curl_loop.py
# async def curl_loop():
#     while True:
#         await aio.sleep(0)
#         CurlLoop.perform()


# Path: falsy/netboy/run.py
import asyncio as aio
import json
import uvloop
from contextlib import suppress
from falsy.netboy.curl_loop import curl_loop





def exception_handler(context):
    print('context:', context)


def run(coro, loop=None):
    async def main_task():
        pycurl_task = aio.ensure_future(curl_loop())
        try:
            r = await coro
        finally:
            pycurl_task.cancel()
            with suppress(aio.CancelledError):
                await pycurl_task
        return r, pycurl_task

    if loop is None:
        loop = uvloop.new_event_loop()
        # loop = aio.get_event_loop()
    aio.set_event_loop(loop)
    loop.set_exception_handler(exception_handler)

    r, _ = loop.run_until_complete(main_task())