miyakogi / pyppeteer

Headless chrome/chromium automation library (unofficial port of puppeteer)
Other
3.57k stars 371 forks source link

High CPU Usage while waiting for connect #275

Open lorien opened 4 years ago

lorien commented 4 years ago

Code:

import asyncio

import pyppeteer

async def main():
    try:
        await asyncio.wait_for(
            pyppeteer.connect(browserWSEndpoint='ws://localhost:3333'),
            timeout=3
        )
    except asyncio.TimeoutError:
        print('Timeout!')

if __name__ == '__main__':
    asyncio.get_event_loop().run_until_complete(main())

Endpoint is broken, port is closed, just random number. If I run python code I'll see 100% CPU usage in top output. If I run it with command sudo perf stat -e 'syscalls:*epoll_wait*' python3 test_wait.py I'll get

 Performance counter stats for 'python3 test_wait.py':

           114,265      syscalls:sys_enter_epoll_wait                                   
           114,265      syscalls:sys_exit_epoll_wait 

So, in 3 seconds it made 100k+ epoll_wait() calls.

I am not expert in asyncio, puppeteer, C programming, syscals, etc. But I think it is not OK :) What do you think?