Lv_task reference does not match

I’d like to use a single task handler for multiple tasks. So inside the handler I’d like to distinguish between the different sources. My idea was to compare the task given to the handler with the one returned at task creation. Surprisingly this comparison fails:

task = None
def my_task(ltask):
    global task
    print(ltask, task, ltask == task)
        
task = lv.task_create(my_task, 1000, lv.TASK_PRIO.MID, None)

and the code prints: struct lv_task_t struct lv_task_t False

Usually one would use the user_data pointer for things like that. But this is already being used by MP itself. Is it possible to retrieve lv_task specific information inside the task handler in MP? I just need to be able to tell inside the handler which of my tasks actually called it. In my example there’s only one task, but there are supposed to be more of them using one single wrapper handler that does some additional magic.

I did similar in lvgl event callbacks and there the comparison works.

Actually, you can use user_data and co-exist with the micropython bindings.
user_data is a dict, and you can set/get entries in it, while the micropython bindings set/get other entries.

But, for your use case, there is a much simpler solution: just pass something to my_task with a lambda function:

def my_task(ltask, id):
    ...

id = <something>
task = lv.task_create(lambda ltask: my_task(ltask, id), 1000, lv.TASK_PRIO.MID, None)

I’m not really sure why it works…
Comparison operators were not implemented for lv bindings Micropython objects.

For all cases I recommend using a lambda like the example above, or something similar such as passing callable objects.

Thanks a lot. Yes, that works fine and also looks much nicer in the event callback.