import threading
import multiprocessing
import random
import time
cc = time .time ( )
def write( name) :
c = time .time ( )
a = '' .join ( [ chr ( random .randint ( 0 , 100 ) ) for _ in range ( 1000000 ) ] )
a = a.encode ( )
with open ( "%s.txt" % name, 'wb' ) as ff:
ff.write ( a)
print ( name, 'done' )
print ( time .time ( ) - c)
for x in range ( 3 ) :
threading .Thread ( target= write, args= ( x, ) ) .run ( )
# from multiprocessing import Pool
# if __name__ == '__main__':
# with Pool(5) as p:
# p.map(write, [1, 2, 3])
# print('total', time.time() - cc)
aW1wb3J0IHRocmVhZGluZwppbXBvcnQgbXVsdGlwcm9jZXNzaW5nCmltcG9ydCByYW5kb20KaW1wb3J0IHRpbWUKCgpjYyA9IHRpbWUudGltZSgpCgoKZGVmIHdyaXRlKG5hbWUpOgogICAgYyA9IHRpbWUudGltZSgpCiAgICBhID0gJycuam9pbihbY2hyKHJhbmRvbS5yYW5kaW50KDAsIDEwMCkpIGZvciBfIGluIHJhbmdlKDEwMDAwMDApXSkKICAgIGEgPSBhLmVuY29kZSgpCiAgICB3aXRoIG9wZW4oIiVzLnR4dCIgJSBuYW1lLCAnd2InKSBhcyBmZjoKICAgICAgICBmZi53cml0ZShhKQogICAgICAgIHByaW50KG5hbWUsICdkb25lJykKICAgIHByaW50KHRpbWUudGltZSgpIC0gYykKCgpmb3IgeCBpbiByYW5nZSgzKToKICAgIHRocmVhZGluZy5UaHJlYWQodGFyZ2V0PXdyaXRlLCBhcmdzPSh4LCkpLnJ1bigpCiMgZnJvbSBtdWx0aXByb2Nlc3NpbmcgaW1wb3J0IFBvb2wKCgojIGlmIF9fbmFtZV9fID09ICdfX21haW5fXyc6CiMgICAgIHdpdGggUG9vbCg1KSBhcyBwOgojICAgICAgICAgcC5tYXAod3JpdGUsIFsxLCAyLCAzXSkKCiMgICAgIHByaW50KCd0b3RhbCcsIHRpbWUudGltZSgpIC0gY2Mp
stdout
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'