Skip to content
Advertisement

Tag: python-asyncio

Running a loop while using telethon

I’m making a telegram channel admin control script that needs checking channel in a loop. I also want some message handlers checking for messages. Here is a part of my code: If i use client.loop.run_until_complete(main()), message handler won’t work but main runs prefectly. and if I use client.run_until_disconnected() and run main in another loop using another thread, it stucks at

Python – getting lost around async

As the title said – I’m having a problem with async stuff. What I’m trying to achieve is written under every function. Sadly in this state of code I’m getting and error: TypeError: object StreamReader can’t be used in ‘await’ expression and at the end RuntimeError: Event loop is closed I was googling for a while and didn’t really find

How to collect wait()’d co-routines in a set?

I have been attempting to generate a ping scan that uses a limited number of processes. I tried as_completed without success and switched to asyncio.wait with asyncio.FIRST_COMPLETED. The following complete script works if the offending line is commented out. I’d like to collect the tasks to a set in order to get rid of pending = list(pending) however pending_set.union(task) throws

How to call synchronous function(s) from async functions in safe manner

What can occur if one or more workers call ‘Synchronous function’ simultaneously ? Maybe one or more workers become blocked for a while ? Answer Short answer: If you call a synchronous (blocking) function from within an async coroutine, all the tasks that are concurrently running in the loop will stall until this function returns. Use loop.run_in_executor(…) to asynchronous run

Python asyncio cancel unawaited coroutines

So given a bit of a complex setup, which is used to generate a list of queries to be run semi-parallel (using a semaphore to not run too many queries at the same time, to not DDoS the server). i have an (in itself async) function that creates a number of queries: Now this works very nicely, executing exactly as

Advertisement