Uh oh!
There was an error while loading. Please reload this page.
bpo-36867: Create the resource_tracker before launching SharedMemoryManagers - #13276
Conversation
f48bd3b to
0c904b5Comparepierreglaser
commented
May 13, 2019
@pitrou how does this look to you? |
Uh oh!
There was an error while loading. Please reload this page.
pitrou
commented
May 13, 2019
I have a more general question: what if the |
pierreglaser
commented
May 13, 2019
@pitrou then most likely the process connecting to the |
pitrou
commented
May 13, 2019
I see. Is there the same problem with semaphores? |
pierreglaser
commented
May 13, 2019
A quick skim through |
pitrou
commented
May 13, 2019
I see. I guess we'll have to live with the limitation. |
pitrou
commented
May 13, 2019
By the way, I noticed that the multiprocessing docs still mention the "semaphore tracker process". This should be fixed. |
pierreglaser
commented
May 13, 2019
OK I'll make a docfix PR. |
pitrou
commented
May 13, 2019
Ok, I'll merge this now. |
Hmm, it seems there are still resource tracker warnings on CI (see e.g. Travis builds). Are they expected? Edit: the warning is from |
There's another Edit: will fix it myself. |
Uh oh!
There was an error while loading. Please reload this page.
pierreglaser
commented
May 13, 2019
@pitrou I could not reproduce the second |
3e6ec27 to
4ef01c8Comparepitrou
commented
May 13, 2019
@pierreglaser You probably needed |
pierreglaser
commented
May 13, 2019
Looking good @pitrou :) |
pitrou
commented
May 13, 2019
Looks like we can move on :-) |
TLDR; The
resource_trackerneeds to be created beforeSharedMemoryManagerprocesses are launched (which is not the case for managers created usingfork)Take this example below:
This simple and legitimate python scripts results in a very noisy output:
Here is why it happens:
smm.start()launches a newmanagerprocess. At this point in the main process, noresource_trackeris created if themanageris launched usingfork.sl = smm.ShareableList(range(10))does two things:resource_tracker.registercall is done ->resource_tracker.ensure_runningis done -> a newresource_trackerprocess is created. In addition, thisresource_trackernow trackssl. However, since the manager process was created before, it does not know that a newresource_trackerprocess was just created in the parent process..slis created, theSharedMemoryManagerasks itsSharedMemoryTracker( which lives in the manager process) to track it.smm.shutdownshuts down the manager. It thus asks theSharedMemoryTrackerto destroysl, which it tracks. To do so,SharedMemory(name)) call, which itself triggers aresource_tracker.registercall ->resource_tracker.ensure_runningcall in the manager process, where no resource_tracker exists yet! Thus, anotherResourceTrackerinstance /process is created and starts trackingslunlinkssl. This sends anunregistercall to the newly createdresource_tracker.When the script ends however, nothing has been done to tell the original
resource_trackercreated in the parent process thatslwas properly unlinked. Theresource_trackerthus thinks a leak happened, and tells the user (first line of my output)). However, there was no leak, asslwas properly unlinked by the manager. Therefore, the cleanup attempt of theresource_trackerfails, resulting the second error.The solution to this problem is simply to create the right before the
managerprocess is created.https://bugs.python.org/issue36867