This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author davin
Recipients davin, juj, sbt
Date 2015-02-20.21:05:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
There are at least two issues at play here.

Running the attached file on OS X produces starkly different results -- console prints:
CREATED TEMP DIRECTORY /var/folders/s4/tc1y5rjx25vfknpzvnfh1b140000gn/T/temp_z6I0BA
ATEXIT: REMOVING TEMP DIRECTORY /var/folders/s4/tc1y5rjx25vfknpzvnfh1b140000gn/T/temp_z6I0BA

The reason only one temp directory is created on OS X (or on other unix-y platforms) and more than one is created on Windows is described in more detail here:

In short, on Windows 8.1, the processes you spawn via multiprocessing must import your main module ("task_spawn" in this case) and in so doing each executes both the line creating a temp directory and the lines following it (this is part of how import works).  I suspect you want instead to put these lines inside a "if __name__ == '__main__'" clause -- doing so will ensure only one temp dir is created and it will be properly cleaned up when the interpreter exits cleanly.  You will have consistent behavior across Windows and unix-y platforms this way too, not to mention your code will more clearly convey that you only want the main process to create a temp dir.  (Specifically see the section "Safe importing of main module" in the docs at the above link.)

That was the first issue -- on to the second.

The registering of functions with atexit means they'll be executed upon "normal interpreter termination".  Lifting a snippet from the atexit docs' introduction section (

  Note: The functions registered via this module are not called when the program is killed by a signal not handled by Python, when a Python fatal internal error is detected, or when os._exit() is called.

When the processes created and managed via multiprocessing reach termination, that is quite different from "normal interpreter termination".  You are observing that when the interpreter's (main) process is done, it executes the function you registered with atexit -- that is how it should be.  Registering functions with atexit inside distinct processes will not cause them to be automagically registered with atexit in the parent interpreter process.

Hopefully with the above explanation in hand it will be possible to make the necessary changes to correct your code without breaking a sweat.
Date User Action Args
2015-02-20 21:05:32davinsetrecipients: + davin, sbt, juj
2015-02-20 21:05:32davinsetmessageid: <>
2015-02-20 21:05:32davinlinkissue23489 messages
2015-02-20 21:05:32davincreate