In [17]:
import time
import threading
from sys import stdout

g = 0

def myfunc(i):
    global g
    
    g += 1
    print "sleeping 5 sec from thread %d; g = %d" % (i, g)
    time.sleep(5)
    print "finished sleeping from thread %d" % i

for i in range(10):
    t = threading.Thread(target=myfunc, args=(i,))
    t.start()
print sorted([thread.name for thread in threading.enumerate()])
print "Give it",
for t in range(6, 0, -1):
    time.sleep(1)
    print t, "seconds..."
    stdout.flush()
print "Hokay."


finished sleeping from thread 0
finished sleeping from thread 1
finished sleeping from thread 2
finished sleeping from thread 3
finished sleeping from thread 4
finished sleeping from thread 5
finished sleeping from thread 6
finished sleeping from thread 7
finished sleeping from thread 8
finished sleeping from thread 9
sleeping 5 sec from thread 0; g = 1
sleeping 5 sec from thread 1; g = 2
sleeping 5 sec from thread 2; g = 3
sleeping 5 sec from thread 3; g = 4
sleeping 5 sec from thread 4; g = 5
sleeping 5 sec from thread 5; g = 6
sleeping 5 sec from thread 6; g = 7
sleeping 5 sec from thread 7; g = 8
sleeping 5 sec from thread 8; g = 9
sleeping 5 sec from thread 9; g = 10
['MainThread', 'Thread-1', 'Thread-159', 'Thread-160', 'Thread-161', 'Thread-162', 'Thread-163', 'Thread-164', 'Thread-165', 'Thread-166', 'Thread-167', 'Thread-168', 'Thread-2', 'Thread-3']
Give it 6 seconds...
5 seconds...
4 seconds...
3 seconds...
finished sleeping from thread 0
finished sleeping from thread 1
finished sleeping from thread 2
finished sleeping from thread 3
finished sleeping from thread 4
finished sleeping from thread 5
finished sleeping from thread 6
finished sleeping from thread 7
finished sleeping from thread 8
finished sleeping from thread 9
2 seconds...
1 seconds...
Hokay.

In [18]:
from multiprocessing import Process

def f(name):
    print 'hello', name

if __name__ == '__main__':
    p = Process(target=f, args=('zogo',))
    p.start()
    p.join()


hello bob

In [ ]: