Why does multiprocess.Process not write the file while threading.Thread does?
Question: The dotestsrl and the dotestmt functions work, and they create and write to
the files. The dotestmp function runs fast, but does not create nor write to
the files. What can I do to make it so that dotestmp performs the same task as
dotestmt but using multiprocessing.Process? (This is on a dual-core,
hyperthreaded machine, running Windows 7 and Python 3.2.3; if that matters)

    
    
    import sys, os, datetime, threading, multiprocessing
    
    def dowrk(fp):
        with open(fp, mode="w") as f:
            for i in range(1000000):
                f.write(str(i))
    
    def dotestsrl():
        fp = "C:\\Users\\user1\\Desktop\\"
        fn = "tst.txt"
        start = datetime.datetime.now()
        for fni in range(1, 5):
            dowrk(fp+str(fni)+fn)
        end = datetime.datetime.now()
        print("***DONE at: ", end - start)
    
    def dotestmt():
        fp = "C:\\Users\\user1\\Desktop\\"
        fn = "tst.txt"
        lst = []
        start = datetime.datetime.now()
        for fni in range(1, 5):
            t = threading.Thread(target=dowrk, args=(fp+str(fni)+fn,))
            lst.append(t)
            t.start()
        for te in lst:
            te.join()
        end = datetime.datetime.now()
        print("***DONE at: ", end - start)
    
    def dotestmp():
        fp = "C:\\Users\\user1\\Desktop\\"
        fn = "tst.txt"
        lsp = []
        start = datetime.datetime.now()
        for fni in range(1, 5):
            p = multiprocessing.Process(target=dowrk, args=(fp+str(fni)+fn,))
            lsp.append(p)
            p.start()
        for pe in lsp:
            pe.join()
        end = datetime.datetime.now()
        print("***DONE at: ", end - start)
    
    dotestsrl() # ***DONE at:  0:00:08.029000
    dotestmt() # ***DONE at:  0:00:07.697000
    dotestmp() #  ***DONE at:  0:00:00.257000, but doesn't actually write files.
    


Answer: You could try:

    
    
    def dowrk_safe(*args, **kwargs):
        try:
            return dowrk(*args, **kwargs)
        except Exception:
            import sys
            import traceback
            traceback.print_exc(file=sys.stderr)
    

instead of `dowrk()` function and see if there are any errors.

