Using yield and return

I have a class with some 10 functions where each of the 10 methods take about 5 seconds to execute.
I am returning something from each of these methods.
Now I included a yield statement

# Perform something
status = "Task #5 done"
yield status
return foo

Issue is, I keep getting an error “Python-3.10 coroutine: AttributeError: ‘generator’ object has no attribute ‘someFunction’”

We really need to see more of the code to help, but it sounds like you’re trying to use yield like an await or unjoined thread, not the typical iterator / generator (doubly so since you have a yield and a return). Further, this seems like a Python issue, not Django-specific.

I got this working successfully by having all the 10 class methods’ code in the same function in views.py by placing yield after each action that was originally in the class’ method. But I am unable to get this working when placed separately in methods of a class.

Yeah, sorry, I’d like to try to help more but I think I need to see more of your code to get a grasp of what you’re trying to do.

The error suggests that you might be trying to use the generator as a coroutine, which is causing confusion. Ensure you’re iterating over the generator correctly with next() or in a loop to obtain values. Ensure that you’re not mistakenly treating it as an async function or coroutine in Python 3.10.