Hello! I decided at the weekend to understand the multiprocessing in python. Because multithreading is locked in GIL, there is a lot of information on the multiprocessing module for paralleling tasks on the Internet
Sketched a test program (os Windows):
import timeit from multiprocessing import Process import os a = timeit.default_timer() def writer(name): print ('start child process with id: ', os.getpid()) with open(name + "txt", 'w') as fout: for i in xrange(500000): print >> fout, name print(timeit.default_timer() - a) if __name__=='__main__': p = Process(target=writer, args=('mom',)) p1 = Process(target=writer, args=('olk',)) p.start() p1.start() print('Done ' + str(timeit.default_timer() - a)) According to my idea, the processes begin to run in parallel in the background, and the sign with Done should appear first. In principle, the way it happens, but with an unpredictable time:
(u'start child process with id: ', 3492) Done 1.73671324643 0.852093865662 (u'start child process with id: ', 4560) 0.933829923571 Where does 1.73671324643 sec come from, after all Done is executed before everyone else?
timer.default_timerwhat (process start?) 2- What isaequal in different processes? - jfsais not a reference point for timeit.default_timer. For example, the starting point for time.time is time.gmtime (0) (1970-01-01). The starting point for time.clock on Windows is the time (wall-clock) elapsed since the first call. What function does timeit.default_timer call on your version of Python? 2- it should be understood thatain one process andain another process are different objects (it is likely that the values are the same, but should be explicitly checked). Try to answer both of the remaining questions from my first comment. - jfs