types.Generator.getstatus
Method on every
generatorReturns the generator's current state as a string.
Return value
One of:
"suspended"- paused at ayield, or not yet resumed for the first time"running"- currently executing (only observable from inside itself)"dead"- returned, or stopped because of an unhandled exception
Notes
A freshly created generator - before its first resume - already reports "suspended", the same as one paused mid-body; there is no separate "not started yet" state.
"dead" is permanent: resume on a dead generator throws resuming dead generator rather than restarting the body. Compare types.Thread.getstatus, whose thread goes back to "idle" instead and can be started again with call.
Example
function geny() { yield 1; return null }
let g = geny()
println("g.getstatus() =", g.getstatus()) // suspended before the first resume too
println("resume g =", resume g)
println("g.getstatus() =", g.getstatus())
println("resume g =", resume g)
println("g.getstatus() =", g.getstatus())
try { resume g } catch(e) { println("resume g throws:", e) }Output:
g.getstatus() = suspended
resume g = 1
g.getstatus() = suspended
resume g = null
g.getstatus() = dead
resume g throws: resuming dead generatorSee also
weakref | Returns a weak reference to the generator. |
getstatus | Returns the thread's current state as a string. |
| generator | class index |