Skip to content

can I declare tasks as async ? #1068

@vladp

Description

@vladp

I am trying to use Playwright async APIs https://playwright.dev/python/docs/library
within a task.

This means (at least that's how I understand it), that I have to declare

@task()
async mytask (ctx):
     async with async_playwright() as p:
        browser = await p.chromium.launch()
        page = await browser.new_page()
        await page.goto("https://playwright.dev")
        print(await page.title())
        await browser.close()

but that does not seem to work, I get:

RuntimeWarning: coroutine 'mytask' was never awaited
executor.execute(*self.tasks)
RuntimeWarning: Enable tracemalloc to get the object allocation traceback

is this possible, or do I need to switch to synchronous playwright APIs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions