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 7998777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T15:18:39+00:00 2026-06-04T15:18:39+00:00

The its-late-and-im-probably-stupid department presents: >>> import multiprocessing >>> mgr = multiprocessing.Manager() >>> d =

  • 0

The its-late-and-im-probably-stupid department presents:

>>> import multiprocessing
>>> mgr = multiprocessing.Manager()
>>> d = mgr.dict()
>>> d.setdefault('foo', []).append({'bar': 'baz'})
>>> print d.items()
[('foo', [])]         <-- Where did the dict go?

Whereas:

>>> e = mgr.dict()
>>> e['foo'] = [{'bar': 'baz'}]
>>> print e.items()
[('foo', [{'bar': 'baz'}])]

Version:

>>> sys.version
'2.7.2+ (default, Jan 20 2012, 23:05:38) \n[GCC 4.6.2]'

Bug or wug?

EDIT: More of the same, on python 3.2:

>>> sys.version
'3.2.2rc1 (default, Aug 14 2011, 21:09:07) \n[GCC 4.6.1]'

>>> e['foo'] = [{'bar': 'baz'}]
>>> print(e.items())
[('foo', [{'bar': 'baz'}])]

>>> id(type(e['foo']))
137341152
>>> id(type([]))
137341152

>>> e['foo'].append({'asdf': 'fdsa'})
>>> print(e.items())
[('foo', [{'bar': 'baz'}])]

How can the list in the dict proxy not contain the additional element?

  • 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-06-04T15:18:40+00:00Added an answer on June 4, 2026 at 3:18 pm

    This is some pretty interesting behavior, I am not exactly sure how it works but I’ll take a crack at why the behavior is the way it is.

    First, note that multiprocessing.Manager().dict() is not a dict, it is a DictProxy object:

    >>> d = multiprocessing.Manager().dict()
    >>> d
    <DictProxy object, typeid 'dict' at 0x7fa2bbe8ea50>
    

    The purpose of the DictProxy class is to give you a dict that is safe to share across processes, which means that it must implement some locking on top of the normal dict functions.

    Apparently part of the implementation here is to not allow you to directly access mutable objects nested inside of a DictProxy, because if that was allowed you would be able to modify your shared object in a way that bypasses all of the locking that makes DictProxy safe to use.

    Here is some evidence that you can’t access mutable objects, which is similar to what is going on with setdefault():

    >>> d['foo'] = []
    >>> foo = d['foo']
    >>> id(d['foo'])
    140336914055536
    >>> id(foo)
    140336914056184
    

    With a normal dictionary you would expect d['foo'] and foo to point to the same list object, and modifications to one would modify the other. As you have seen, this is not the case for the DictProxy class because of the additional process safety requirement imposed by the multiprocessing module.

    edit: The following note from the multiprocessing documentation clarifies what I was trying to say above:


    Note: Modifications to mutable values or items in dict and list proxies will not be propagated through the manager, because the proxy has no way of knowing when its values or items are modified. To modify such an item, you can re-assign the modified object to the container proxy:

    # create a list proxy and append a mutable object (a dictionary)
    lproxy = manager.list()
    lproxy.append({})
    # now mutate the dictionary
    d = lproxy[0]
    d['a'] = 1
    d['b'] = 2
    # at this point, the changes to d are not yet synced, but by
    # reassigning the dictionary, the proxy is notified of the change
    lproxy[0] = d
    

    Based on the above information, here is how you could rewrite your original code to work with a DictProxy:

    # d.setdefault('foo', []).append({'bar': 'baz'})
    d['foo'] = d.get('foo', []) + [{'bar': 'baz'}]
    

    As Edward Loper suggested in comments, edited above code to use get() instead of setdefault().

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

Sidebar

Related Questions

Its getting a bit late so excuse me if I am making a stupid
Its late and I probably should sleep on this. Easy one I have 3
OK its late so I must be doing something stupid, but myreduction for loop
Probably an ultra-stupid question, but it's late, i'm tired and dinners nearly ready.... Here's
It's probably late and I have missed this off by a long shot. I
it's late, I'm tired, and probably being quite dense.... I have written an application
Sorry to ask, its late and I can't figure a way to do it...
guess its getting late, and Im a beginner, just need a little help.. Im
Probably a simple solution but I'm stuck and it's late... :) $j('#thisImage').html('<img src=image.jpg id=box
Ok its late and I am not catching why this is broken. So here

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.