| Line 400: |
Line 400: |
| | # Do stuff | | # Do stuff |
| | ssh_proc.terminate() | | ssh_proc.terminate() |
| | + | </source> |
| | + | == Multithreading == |
| | + | <source lang="python"> |
| | + | #!/usr/bin/python |
| | + | |
| | + | import thread |
| | + | import time |
| | + | |
| | + | #Define a function for the thread |
| | + | def print_time( threadName, delay): |
| | + | count = 0 |
| | + | while count < 5: |
| | + | time.sleep(delay) |
| | + | count += 1 |
| | + | print "%s: %s" % ( threadName, time.ctime(time.time()) ) |
| | + | |
| | + | # Create two threads as follows |
| | + | try: |
| | + | thread.start_new_thread( print_time, ("Thread-1", 2, ) ) |
| | + | thread.start_new_thread( print_time, ("Thread-2", 4, ) ) |
| | + | except: |
| | + | print "Error: unable to start thread" |
| | + | |
| | + | while 1: |
| | + | pass |
| | + | </source> |
| | + | (*) see also threading module: |
| | + | <source lang="python"> |
| | + | import threading |
| | </source> | | </source> |