-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
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_tracker
needs to be created beforeSharedMemoryManager
processes 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 newmanager
process. At this point in the main process, noresource_tracker
is created if themanager
is launched usingfork
.sl = smm.ShareableList(range(10))
does two things:resource_tracker.register
call is done ->resource_tracker.ensure_running
is done -> a newresource_tracker
process is created. In addition, thisresource_tracker
now trackssl
. However, since the manager process was created before, it does not know that a newresource_tracker
process was just created in the parent process..sl
is created, theSharedMemoryManager
asks itsSharedMemoryTracker
( which lives in the manager process) to track it.smm.shutdown
shuts down the manager. It thus asks theSharedMemoryTracker
to destroysl
, which it tracks. To do so,SharedMemory(name)
) call, which itself triggers aresource_tracker.register
call ->resource_tracker.ensure_running
call in the manager process, where no resource_tracker exists yet! Thus, anotherResourceTracker
instance /process is created and starts trackingsl
unlinks
sl
. This sends anunregister
call to the newly createdresource_tracker
.When the script ends however, nothing has been done to tell the original
resource_tracker
created in the parent process thatsl
was properly unlinked. Theresource_tracker
thus thinks a leak happened, and tells the user (first line of my output)). However, there was no leak, assl
was properly unlinked by the manager. Therefore, the cleanup attempt of theresource_tracker
fails, resulting the second error.The solution to this problem is simply to create the right before the
manager
process is created.https://bugs.python.org/issue36867