dabeaz / curio

Good Curio!
Other
4.02k stars 241 forks source link

Better naming for tasks #175

Closed jkbbwr closed 7 years ago

jkbbwr commented 7 years ago

So I have a structure at the moment that looks like this

import curio
class Base:
    async def loop(self):
        pass
    async def run(self):
        while True:
            await self.loop()

class Something(Base):
    async def loop(self):
        await curio.sleep(1)
        print("looping in %s" % await curio.current_task())

s = Something()
curio.run(s.run())

Now because it was Base.run that was scheduled as a task in run it will report Base.run every time. This is less helpful when debugging in the monitor as it shows and I don't know which of those Bases is which task.

0      READ_WAIT    337        None    Kernel._run.<locals>._kernel_task                 
1      QUEUE_GET    1          None    Monitor.monitor_task                              
2      QUEUE_GET    1          None    Base.run                                     
3      FUTURE_WAIT  1          None    UniversalQueue._get_helper                        
4      QUEUE_GET    96717      0.00036 Base.run                                     
5      TASK_JOIN    37277      None    Base.run                                     
6      QUEUE_GET    46194      0.05448 Base.run    

Is there a way that I could hint to curio what to name a task, or provide some attribute or API for renaming a task to something useful after scheduling.

dabeaz commented 7 years ago

Good idea. I'll make something.

dabeaz commented 7 years ago

I've added a .name attribute to Task instances that can be set to whatever you want. str(Task) returns this value.

jkbbwr commented 7 years ago

Wicked! Makes debugging easier shall we close this?