< expLog

Coroutine Objects

Coroutine Objects

The object maintains a link to the actual code to be executed, as well as the state of execution by keeping the frame around. This is what makes it possible to "pause" and "resume" a coroutine when out-of-band mechanisms return.

Listing out the non-dunder methods to see what's available with the object.

instance = hello_world()
print([(type(getattr(instance, attribute)), attribute) for attribute in instance.__dir__() if not attribute.startswith("__")])

Comparing the attributes to confirm that the code is shared

instance_a = hello_world()
instance_b = hello_world()