| 21 | |
| 22 | @async |
| 23 | def test(): |
| 24 | # We start in the main thread |
| 25 | print "1 %s" % threading.currentThread() |
| 26 | yield |
| 27 | |
| 28 | # This part is run in a seperate thread, not blocking the main thread |
| 29 | print "2 %s" % threading.currentThread() |
| 30 | yield |
| 31 | |
| 32 | # Now we are back in the main thread |
| 33 | print "3 %s" % threading.currentThread() |
| 34 | yield |
| 35 | |
| 36 | # And in another background thread |
| 37 | print "4 %s" % threading.currentThread() |
| 38 | yield |
| 39 | |
| 40 | # And we keep all internal variables between the threads! |
| 41 | print "5 %s" % threading.currentThread() |
| 42 | |
| 43 | if __name__ == "__main__": |
| 44 | test() |