Skip to content

Example code appears to discard reference to the created task #98

@AlexanderWells-diamond

Description

@AlexanderWells-diamond

The aiohttp_fetch.py example file makes use of the @asyncSlot() decorator to allow passing the on_btnFetch_clicked async function to the .connect method of a button.

Under the covers, @asyncSlot() is just creating a Task object using asyncio.ensure_future(). In the documentation for that function, it says "Save a reference to the result of this function, to avoid a task disappearing mid-execution.". It seems that the example code does not do this, so may be liable for garbage-collection issues if the now reference-less task is cleaned up unexpectedly.

Is there a preferred pattern to use for these decorators? Or can the decorator be modified to keep a reference to the Task that is created?

Metadata

Metadata

Assignees

No one assigned

    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