Question

I was following the Python 3 Docs to learn Multiprocessing, but I noticed something strange that I hadn't noticed before. After running the script the code is then compiled into a working standalone binary in a "pycache" directory. Can somebody please explain this to me? I am using Windows 8 and Python 3.3 if it matters (AMD64 for both). Thank you.

from multiprocessing import Process

def f(name):
    print('hello',name)

if __name__ == '__main__':
    for i in range(5):
        p = Process(target=f, args=('bob',))
        p.start()
        p.join()
    input() #Added this so that I can see my results.

Tutorial I was following: http://docs.python.org/3.3/library/multiprocessing.html

Was it helpful?

Solution

When a module is imported, Python will cache the bytecode so it doesn't need to reparse the file. The cached bytecode goes in a __pycache__ folder. multiprocessing implicitly imports your module, so it is cached. It can be safely ignored, as Python is smart and will not use it if it is out of date. If you really don't want it to be making those directories and files everywhere, set the environment variable PYTHONDONTWRITEBYTECODE to 1.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top