fork(1) download
  1. #!/usr/bin/env python3
  2.  
  3. from inspect import getgeneratorstate
  4.  
  5. def coroutine(func):
  6. def inner(*args, **kwargs):
  7. g = func(*args, **kwargs)
  8. g.send(None)
  9. return inner
  10.  
  11. @coroutine
  12. def average():
  13. count = 0
  14. summ = 0
  15. average = None
  16. print('init')
  17.  
  18. while True:
  19. try:
  20. x = yield average
  21. except StopIteration:
  22. print('Done')
  23. else:
  24. count += 1
  25. summ += x
  26. average = round(summ / count, 2)
  27.  
  28.  
  29. g = average()
  30. print(getgeneratorstate(g))
Runtime error #stdin #stdout #stderr 0.03s 30680KB
stdin
Standard input is empty
stdout
init
stderr
Traceback (most recent call last):
  File "./prog.py", line 30, in <module>
  File "/usr/lib/python3.5/inspect.py", line 1580, in getgeneratorstate
    if generator.gi_running:
AttributeError: 'NoneType' object has no attribute 'gi_running'