Ticket #321: littlethreadtest.py
| Line | |
|---|---|
| 1 | import threading |
| 2 | import time |
| 3 | |
| 4 | |
| 5 | def count_to_10(): |
| 6 | n = 1 |
| 7 | while n <= 10: |
| 8 | yield n |
| 9 | n += 1 |
| 10 | time.sleep(1) |
| 11 | |
| 12 | def child_thread(): |
| 13 | ten = count_to_10() |
| 14 | for n in ten: |
| 15 | print n |
| 16 | |
| 17 | |
| 18 | if __name__ == '__main__': |
| 19 | c = threading.Thread(target=child_thread) |
| 20 | me = threading.currentThread() |
| 21 | c.start() |
| 22 | print me.getName(), "is done - cya!" |

