Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def fac(a):
- if a <= 1: return 1
- return a * fac(a-1)
- def a(n):
- import time
- t = time.time()
- c = time.clock()
- for i in range(200, 900):
- f = fac(i)
- s = "Thread %d: %d -> (X)" % (n, i,) # fac(i))
- s += "@ t:%f c:%f" % (time.time() - t, time.clock() - c)
- print s
- if 1:
- import os
- #Fork bomb alarm: 3 leads to 8 processes!
- #for i in range(3): os.fork()
- pids = [os.fork() for i in range(3)]
- print pids
- import time
- time.sleep(.7)
- # now the show begins:
- a(os.getpid())
- else:
- import threading
- threads = [threading.Thread(target=a, args=(i,)) for i in range(10)]
- for t in threads: t.start()
- for t in threads: t.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement