fork download
  1. import threading
  2. import multiprocessing
  3. import random
  4. import time
  5.  
  6.  
  7. cc = time.time()
  8.  
  9.  
  10. def write(name):
  11. c = time.time()
  12. a = ''.join([chr(random.randint(0, 100)) for _ in range(1000000)])
  13. a = a.encode()
  14. with open("%s.txt" % name, 'wb') as ff:
  15. ff.write(a)
  16. print(name, 'done')
  17. print(time.time() - c)
  18.  
  19.  
  20. for x in range(3):
  21. threading.Thread(target=write, args=(x,)).run()
  22. # from multiprocessing import Pool
  23.  
  24.  
  25. # if __name__ == '__main__':
  26. # with Pool(5) as p:
  27. # p.map(write, [1, 2, 3])
  28.  
  29. # print('total', time.time() - cc)
Runtime error #stdin #stdout #stderr 2.89s 13120KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 21, in <module>
  File "/usr/lib/python3.4/threading.py", line 868, in run
    self._target(*self._args, **self._kwargs)
  File "./prog.py", line 14, in write
PermissionError: [Errno 13] Permission denied: '0.txt'