fork(8) download
  1. #!/usr/bin/env python3
  2. from contextlib import ExitStack
  3. from functools import partial
  4.  
  5. print("counting")
  6. with ExitStack() as stack:
  7. for i in range(10):
  8. a = i
  9. stack.callback(partial(print, a, i))
  10.  
  11. x = 42
  12. a = x
  13. print("done")
Success #stdin #stdout 0.03s 10280KB
stdin
Standard input is empty
stdout
counting
done
9 9
8 8
7 7
6 6
5 5
4 4
3 3
2 2
1 1
0 0