Skip to content

discord.ext.tasks.loop stores task globally #2294

@dfitzpatrick

Description

@dfitzpatrick

Summary

discord.ext.Tasks stores the current task in _task and will not spawn another instance of it.

I assume this was designed at COG level, but suppose you have a custom class that you have a unique task start in, you cannot instantiate more than one class with that task.

Reproduction Steps

create custom class with a task

Expected Results

Tasks should not be global to the package, but to the instance.

Actual Results

dispatches command_error at the COG level that the Task already exists.

 if self._task is not None and not self._task.done():
            raise RuntimeError('Task is already launched and is not completed.')

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

System Information

Python v3.6.7-final

  • discord.py v1.2.3-final
  • aiohttp v3.5.4
  • websockets v6.0
  • system info: Windows 10 10.0.18362

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugThis is a bug with the library.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions