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

  • Home
  • SEARCH
  • 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 8868917
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:21:59+00:00 2026-06-14T17:21:59+00:00

The dict ‘params’ in the object ‘test’ cannot be updated when using pp module.

  • 0

The dict ‘params’ in the object ‘test’ cannot be updated when using pp module. Who can tell me why this would happen? Just look at the codes:

import pp

class test(object):
    params = {'n': None}
    dic2 = {}
    n = None

    def __init__(self, i):
        #won't change
        self.params['n'] = i
        #changed
        self.n = i
        self.dic2 = {i: i}

    def run(self):
        print self.n, self.params, self.dic2

job_server = pp.Server()

jobs = []

for i in xrange(10):
    t = test(i)
    #won't change
    t.params['n'] = i
    #changed
    t.n = i
    t.run()
    jobs.append(job_server.submit(t.run))

[job() for job in jobs]

The results:

0 {'n': 0} {0: 0}
1 {'n': 1} {1: 1}
2 {'n': 2} {2: 2}
3 {'n': 3} {3: 3}
4 {'n': 4} {4: 4}
0 {'n': None} {0: 0}
1 {'n': None} {1: 1}
2 {'n': None} {2: 2}
3 {'n': None} {3: 3}
4 {'n': None} {4: 4}

as we can see when using pp, the “params[‘n’]” can not be updated. It’s a strange behaviour. How could this happen?

  • 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-14T17:22:00+00:00Added an answer on June 14, 2026 at 5:22 pm

    This is a common pitfall of multiprocessing modules.

    When you do calls like job_server.submit(t.run), the object t is pickled, sent to a new process, unpickled, run is executed and the return value is pickled, sent back to the main process and unpickled.

    Now, class pickling is not really supported(see here). pickle just pickles the name and when unpickling it re-imports the module to obtain the class object.

    Since the variables you are using are class variables, they get reinitialized when the module is reimported. The same would happen for functions’ attributes.

    If you want to keep the values of those variables you must make them instance variables.

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

Sidebar

Related Questions

if ([dict objectForKey:@photo] !=(id)[NSNull null]) {NSLOG(@dictinary is not empty)} This is not working for
NSDictionary *dict = [NSDictionary dictionaryWithObjectsAndKeys:@Please, other format selected., NSLocalizedDescriptionKey, @This format is not available.,
suppose d is a dict d={' a ':1,'b ':2} if we give like this
I've got a dict that looks something like this: d = {'Food': {'Fruit' :
i've got a dict generated at somewhere like this: d={ 'k1':'v1', 'k2':'v2', ... }
d3 = dict(d1, **d2) I understand that this merges the dictionary. But, is it
I have this dict in python; d={} d['b']='beta' d['g']='gamma' d['a']='alpha' when i print the
I have a dict that looks like this { keyword1:3 , keyword2:1 , keyword3:5
Python dict key delete, if key pattern match with other dict key. e.g. a={'a.b.c.test':1,
I have a nested dict like this d={ time1 : column1 : {data1,data2,data3} column2

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.