-
-
Notifications
You must be signed in to change notification settings - Fork 33.7k
bpo-36867: Create the resource_tracker before launching SharedMemoryManagers #13276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
bpo-36867: Create the resource_tracker before launching SharedMemoryManagers #13276
Conversation
f48bd3b to
0c904b5
Compare
auvipy
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no test?
|
@pitrou how does this look to you? |
|
I have a more general question: what if the |
|
@pitrou then most likely the process connecting to the |
|
I see. Is there the same problem with semaphores? |
|
A quick skim through |
|
I see. I guess we'll have to live with the limitation. |
|
By the way, I noticed that the multiprocessing docs still mention the "semaphore tracker process". This should be fixed. |
|
OK I'll make a docfix PR. |
|
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. |
|
@pitrou I could not reproduce the second |
3e6ec27 to
4ef01c8
Compare
|
@pierreglaser You probably needed |
|
Looking good @pitrou :) |
|
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