Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

Patch loop runner _run_once

import asyncio
def _run_once(self):
	num_tasks = len(self._scheduled)
    print("num tasks in queue: {}".format(num_tasks))
    super(asyncio.SelectorEventLoop, self)._run_once()

EventLoop = asyncio.SelectorEventLoop
EventLoop._run_once = _run_once
loop = EventLoop()
asyncio.set_event_loop(loop)
async def task(n):
    await asyncio.sleep(n)
    print("sleep: {} sec".format(n))

coro = loop.create_task(task(3))
loop.run_until_complete(coro)
# num tasks in queue: 0
# num tasks in queue: 1
# num tasks in queue: 0
# sleep: 3 sec
# num tasks in queue: 0
loop.close()
Comment

PREVIOUS NEXT
Code Example
Python :: python write to error stream 
Python :: tessellation 
Python :: how to count the iteration a list python 
Python :: python programming online editor 
Python :: python string: string concatenation 
Python :: metodo estatico de python 
Python :: a string varible in python 
Python :: what is a rare earth 
Python :: def multiply(a b) a * b 
Python :: pyqt fixed window size 
Python :: how to increment datetime by custom months in python 
Python :: typing return two objects 
Python :: how to stop a while loop in opencv 
Python :: was en francais 
Python :: #finding the differences between setA and SetB: 
Python :: dadfa 
Python :: refresh tab selenium python 
Python :: pillow update image 
Python :: 144/360 
Python :: add legend to px.choropleth map python 
Python :: pandas join non-unique 
Python :: Method to get column average 
Python :: round to nearest multiple of 5 python from both end 
Python :: pycharm writing issue 
Python :: multiclass.roc plot title 
Python :: ec2 ssh terminal hangs after sometime 
Python :: sklearn recognising sentences 
Python :: pandas resample fill missing values 
Python :: fibonacci numbers function python print 
Python :: fake-useragent proxy webscraping browser change 
ADD CONTENT
Topic
Content
Source link
Name
4+9 =