Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class page must be an inheritance of AsyncIOEventEmitter instead base EventEmitter class to use method page.on's callback in coroutine #258

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from

Conversation

artyl
Copy link

@artyl artyl commented May 14, 2021

Starting with pyee ver 8.x.x default class EventEmitter lost ability to run coroutines using asyncio.ensure_future
This functionality in pyee provided by special class - AsyncIOEventEmitter (see help(pyee.AsyncIOEventEmitter))

So code that uses asyncio.ensure_future would throw error with pyee version >=8.0.0

Latest pyppeteer (pyppeteer-0.2.5) code has dependencies pyee (>=8.1.0,<9.0.0)

How to reproduce problem:

import asyncio
from pyppeteer import launch

async def response_worker(response):
    print(f'response:{response.request.url}')

async def main():
    browser = await launch()
    page = await browser.newPage()
    page.on("response", response_worker)
    await page.goto('https://example.com')
    await asyncio.sleep(3)
    await browser.close()

asyncio.run(main())

pyee <8.0.0 works properly, response_worker will be called

response:https://example.com/

pyee >= 8.0.0 gives warning, response_worker will not be called

pyee/_base.py:81: RuntimeWarning: coroutine 'response_worker' was never awaited
f(*args, **kwargs)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

… EventEmitter class to use method page.on's callback in coroutine
@artyl
Copy link
Author

artyl commented May 15, 2021

the pyppeteer.browser.Browser class seems to have a similar problem with method browser.on("disconnected", ...)
and must be AsyncIOEventEmitter

…ase EventEmitter class to use method browser.on's callback in coroutine
@PPX47
Copy link

PPX47 commented May 15, 2021

Thanks for this! Waiting for merge!

@Mattwmaster58 Mattwmaster58 added the fixed-in-2.1.1 Issue is already fixed in WIP pup2.1.1 branch label Aug 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed-in-2.1.1 Issue is already fixed in WIP pup2.1.1 branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants