Python Forum
How to get coroutine from a task, and an object from a coroutine?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to get coroutine from a task, and an object from a coroutine?
#1
Python 3.5

I have an object, one of the methods of which is coroutine:
class A:
    def __init__(self):
        self.number = random.random()

    async def my_method(self):
       asyncio.sleep(1)
       print('Hello, world!')
I create task:
async def add_task(tasks:list):
    a = A()
    coro = a.my_method()
    task = asyncio.create_task(coro)
    tasks.append(task)
How can I get object 'a' from tasks[0]?
Reply


Messages In This Thread
How to get coroutine from a task, and an object from a coroutine? - by AlekseyPython - Mar-23-2019, 07:48 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Coroutine was never awaited error bucki 1 665 Sep-23-2023, 08:17 PM
Last Post: deanhystad
  count certain task in task manager[solved] kucingkembar 2 1,138 Aug-29-2022, 05:57 PM
Last Post: kucingkembar
  Schedule a task and render/ use the result of the task in any given time klllmmm 2 2,110 May-04-2021, 10:17 AM
Last Post: klllmmm
  How to create a task/import a task(task scheduler) using python Tyrel 7 3,763 Feb-11-2021, 11:45 AM
Last Post: Tyrel
  How to add coroutine to a running event loop? AlekseyPython 1 8,173 Mar-21-2019, 06:04 PM
Last Post: nilamo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020