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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T14:58:54+00:00 2026-05-27T14:58:54+00:00

I tried to share data when using the multiprocessing module (python 2.7, Linux), I

  • 0

I tried to share data when using the multiprocessing module (python 2.7, Linux), I got different results when using slightly different code:

import os
import time
from multiprocessing import Process, Manager

def editDict(d):
    d[1] = 10
    d[2] = 20
    d[3] = 30


pnum = 3
m = Manager()

1st version:

mlist = m.list()
for i in xrange(pnum):
    mdict = m.dict()
    mlist.append(mdict)
    p = Process(target=editDict,args=(mdict,))
    p.start()

time.sleep(2)
print 'after process finished', mlist

This generates:

after process finished [{1: 10, 2: 20, 3: 30}, {1: 10, 2: 20, 3: 30}, {1: 10, 2: 20, 3: 30}]

2nd version:

mlist = m.list([m.dict() for i in xrange(pnum)]) # main difference to 1st version
for i in xrange(pnum):
    p = Process(target=editDict,args=(mlist[i],))
    p.start()
time.sleep(2)
print 'after process finished', mlist

This generates:

after process finished [{}, {}, {}]

I do not understand why the outcome is so different.

  • 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-27T14:58:55+00:00Added an answer on May 27, 2026 at 2:58 pm

    It is because you access the variable by the list index the second time, while the first time you pass the actual variable. As stated in the multiprocessing docs:

    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.

    This means that, to keep track of items that are changed within a container (dictionary or list), you must reassign them after each edit. Consider the following change (for explanatory purposes, I’m not claiming this to be clean code):

    def editDict(d, l, i):
        d[1] = 10
        d[2] = 20
        d[3] = 30
        l[i] = d
    
    mlist = m.list([m.dict() for i in xrange(pnum)])
    for i in xrange(pnum):
        p = Process(target=editDict,args=(mlist[i], mlist, i,))
        p.start()
    

    If you will now print mlist, you’ll see that is has the same output as your first attempt. The reassignment will allow the container proxy to keep track of the updated item again.

    Your main issue in this case is that you have a dict (proxy) inside a list proxy: updates to the contained container won’t be noticed by the manager, and hence not have the changes you expected it to have. Note that the dictionary itself will be updated in the second example, but you just don’t see it since the manager didn’t sync.

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

Sidebar

Related Questions

I'm using EGODatabase to process my data. When I tried to insert data into
I'm using Highcharts to represent groups of time series. So, data points collected from
Helllo, I would like to share small amounts of data (< 1K) between python
I tried to compile the code using g++4.4.6 on aix 6.1. I dont have
Mono claims to be compatible with .NET. Have you tried it? Can you share
when I tried to create a shared library file using the cl command in
I am working on a kernel module which needs to work on data from
I'm trying to write a secure transfer file program using Python and AES and
In the last month, we've had a persistent problem with the Python 2.6.x multiprocessing
I'm encountering a very annoying error using Core Data on Mac OS X 10.5.

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.