'What's "method 'poll' of 'select.epoll' objects"?
I added the following to print the performance stats
import cProfile
import pstats
pr = cProfile.Profile()
pr.enable()
And the output shows most of the time were used by method 'poll' of 'select.epoll' objects. What is it?
ncalls tottime percall cumtime percall filename:lineno(function)
1045 8.123 0.008 8.123 0.008 {method 'poll' of 'select.epoll' objects}
723 0.865 0.001 0.865 0.001 {method 'recv' of '_socket.socket' objects}
500 0.109 0.000 0.109 0.000 encoder.py:204(iterencode)
540 0.066 0.000 0.066 0.000 {method 'acquire' of '_thread.lock' objects}
1045 0.012 0.000 9.257 0.009 base_events.py:1335(_run_once)
2843 0.006 0.000 1.111 0.000 events.py:143(_run)
500 0.005 0.000 0.115 0.000 encoder.py:182(encode)
1045 0.005 0.000 8.129 0.008 selectors.py:428(select)
501 0.004 0.000 0.004 0.000 events.py:638(_get_running_loop)
500 0.004 0.000 0.008 0.000 futures.py:381(_chain_future)
1000 0.004 0.000 0.214 0.000 test.py:29(parse_and_save_article)
4001 0.003 0.000 0.003 0.000 {built-in method builtins.hasattr}
2001 0.003 0.000 0.006 0.000 base_events.py:594(_call_soon)
500 0.003 0.000 0.016 0.000 futures.py:361(_copy_future_state)
342 0.002 0.000 0.868 0.003 selector_events.py:138(_read_from_self)
2001 0.002 0.000 0.008 0.000 base_events.py:564(call_soon)
2001 0.002 0.000 0.002 0.000 events.py:104(__init__)
500 0.002 0.000 0.076 0.000 thread.py:114(submit)
4000 0.002 0.000 0.005 0.000 base_futures.py:23(isfuture)
500 0.002 0.000 0.004 0.000 base_events.py:277(create_task)
3010 0.002 0.000 0.003 0.000 threading.py:239(__enter__)
500 0.002 0.000 0.012 0.000 futures.py:420(wrap_future)
1000 0.002 0.000 0.095 0.000 test.py:50(run)
I created a decorator to convert synchronous functions to async functions.
def wrap(func):
@wraps(func)
async def run(*args, loop=None, executor=None, **kwargs):
if loop is None:
loop = asyncio.get_event_loop()
pfunc = partial(func, *args, **kwargs)
return await loop.run_in_executor(executor, pfunc)
return run
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
