Passing args, kwargs, to run_in_executor

Use functools.partial; it’s a standard way to do such things, and it’s specifically recommended in the docs for loop.run_in_executor, as well as more generally in the Event Loop docs. Here’s how it might look for you: import functools # at the top with the other imports loop.run_in_executor(None, functools.partial(update_contacts, data={ ’email’: email, ‘access_token’: g.tokens[‘access_token’] })) You … Read more

aiogevent event loop “fails” to track greenlets

Taking a guess at this, but I think you’re using the event loop wrong for asyncio. I don’t know enough about gevent to understand what type of object it’s creating to know if this will work. The documentation would indicate that the order in which stop() and run_forever() are called is relevant to the operational … Read more

How to create a Python decorator that can wrap either coroutine or function?

May be you can find better way to do it, but, for example, you can just move your wrapping logic to some context manager to prevent code duplication: import asyncio import functools import time from contextlib import contextmanager def duration(func): @contextmanager def wrapping_logic(): start_ts = time.time() yield dur = time.time() – start_ts print(‘{} took {:.2} … Read more

python asyncio, how to create and cancel tasks from another thread

I think you may need to make your add_task method aware of whether or not its being called from a thread other than the event loop’s. That way, if it’s being called from the same thread, you can just call asyncio.async directly, otherwise, it can do some extra work to pass the task from the … Read more

“async with” in Python 3.4

Just don’t use the result of session.get() as a context manager; use it as a coroutine directly instead. The request context manager that session.get() produces would normally release the request on exit, but so does using response.text(), so you could ignore that here: @asyncio.coroutine def fetch(session, url): with aiohttp.Timeout(10): response = yield from session.get(url) return … Read more

asyncio: Is it possible to cancel a future been run by an Executor?

In this case, there is no way to cancel the Future once it has actually started running, because you’re relying on the behavior of concurrent.futures.Future, and its docs state the following: cancel() Attempt to cancel the call. If the call is currently being executed and cannot be cancelled then the method will return False, otherwise … Read more

Why does the asyncio’s event loop suppress the KeyboardInterrupt on Windows?

There is workaround for Windows. Run another corouting which wake up loop every second and allow loop to react on keyboard interrupt Example with Echo server from asyncio doc async def wakeup(): while True: await asyncio.sleep(1) loop = asyncio.get_event_loop() coro = loop.create_server(EchoServerClientProtocol, ‘127.0.0.1’, 8888) server = loop.run_until_complete(coro) # add wakeup HACK loop.create_task(wakeup()) try: loop.run_forever() except … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)