Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7563047
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T13:33:57+00:00 2026-05-30T13:33:57+00:00

I have a concern about multiprocessing.Manager() in python. Here is the example: import multiprocessing

  • 0

I have a concern about multiprocessing.Manager() in python. Here is the example:

import multiprocessing

def f(ns):
    ns.x *=10
    ns.y *= 10

if __name__ == '__main__':
    manager = multiprocessing.Manager()
    ns = manager.Namespace()
    ns.x = 1
    ns.y = 2

    print 'before', ns
    p = multiprocessing.Process(target=f, args=(ns,))
    p.start()
    p.join()
    print 'after', ns

and the output is:

before Namespace(x=1, y=2)
after Namespace(x=10, y=20)

Until now, it worked as I expected, then I modified the code like this:

import multiprocessing

def f(ns):
    ns.x.append(10)
    ns.y.append(10)

if __name__ == '__main__':
    manager = multiprocessing.Manager()
    ns = manager.Namespace()
    ns.x = []
    ns.y = []

    print 'before', ns
    p = multiprocessing.Process(target=f, args=(ns,))
    p.start()
    p.join()
    print 'after', ns

Now the output is:

before Namespace(x=[], y=[])
after Namespace(x=[], y=[])

It confuses me why the lists were not changed as I expected. Can anyone help me to figure out what happened?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T13:33:58+00:00Added an answer on May 30, 2026 at 1:33 pm

    Manager proxy objects are unable to propagate changes made to (unmanaged) mutable objects inside a container. So in other words, if you have a manager.list() object, any changes to the managed list itself are propagated to all the other processes. But if you have a normal Python list inside that list, any changes to the inner list are not propagated, because the manager has no way of detecting the change.

    In order to propagate the changes, you have to use manager.list() objects for the nested lists too (requires Python 3.6 or newer), or you need to modify the manager.list() object directly (see the note on manager.list in Python 3.5 or older).

    For example, consider the following code and its output:

    import multiprocessing
    import time
    
    def f(ns, ls, di):
        ns.x += 1
        ns.y[0] += 1
        ns_z = ns.z
        ns_z[0] += 1
        ns.z = ns_z
    
        ls[0] += 1
        ls[1][0] += 1 # unmanaged, not assigned back
        ls_2 = ls[2]  # unmanaged...
        ls_2[0] += 1
        ls[2] = ls_2  # ... but assigned back
        ls[3][0] += 1 # managed, direct manipulation
    
        di[0] += 1
        di[1][0] += 1 # unmanaged, not assigned back
        di_2 = di[2]  # unmanaged...
        di_2[0] += 1
        di[2] = di_2  # ... but assigned back
        di[3][0] += 1 # managed, direct manipulation
    
    if __name__ == '__main__':
        manager = multiprocessing.Manager()
        ns = manager.Namespace()
        ns.x = 1
        ns.y = [1]
        ns.z = [1]
        ls = manager.list([1, [1], [1], manager.list([1])])
        di = manager.dict({0: 1, 1: [1], 2: [1], 3: manager.list([1])})
    
        print('before', ns, ls, ls[2], di, di[2], sep='\n')
        p = multiprocessing.Process(target=f, args=(ns, ls, di))
        p.start()
        p.join()
        print('after', ns, ls, ls[2], di, di[2], sep='\n')
    

    Output:

    before
    Namespace(x=1, y=[1], z=[1])
    [1, [1], [1], <ListProxy object, typeid 'list' at 0x10b8c4630>]
    [1]
    {0: 1, 1: [1], 2: [1], 3: <ListProxy object, typeid 'list' at 0x10b8c4978>}
    [1]
    after
    Namespace(x=2, y=[1], z=[2])
    [2, [1], [2], <ListProxy object, typeid 'list' at 0x10b8c4630>]
    [2]
    {0: 2, 1: [1], 2: [2], 3: <ListProxy object, typeid 'list' at 0x10b8c4978>}
    [2]
    

    As you can see, when a new value is assigned directly to the managed container, it changes; when it is assigned to a mutable container within the managed container, it doesn’t change; but if the mutable container is then reassigned to the managed container, it changes again. Using a nested managed container also works, detecting changes directly without having to assign back to the parent container.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have little concern about register BroadcastReceiver : Because Android support quite flexible, it
I have a concern about the separate line under navigation bar. Please take a
Recently, I found myself having to write up some concerns I have about race
I have a date import project in which the clients send ANSI-latin1 encoded files
I'd appreciate some opinions on a concern I have. I have a [User] table
I mostly work on CMSs, where there is no security concern about the people
My concern is about what will use stack memory in an instruction involving arithmetics
I Have a form with one textbox called(ProductTitle) if I write as example Étuit
I have some concerns related to the fact of testing some functions containing the
We're building a multi-language Drupal stack and one of the concerns we have is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.