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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T03:31:26+00:00 2026-05-31T03:31:26+00:00

the output is like this, so strange, as I thought in the run function,

  • 0

the output is like this, so strange, as I thought in the run function, it should also output the list data
list running []
append list [1]
list running []
append list [1, 2]
list running []
append list [1, 2, 3]
list running []
append list [1, 2, 3, 4]
list running []
append list [1, 2, 3, 4, 5]

from multiprocessing import Process

class A(Process):

    def __init__(self):
        Process.__init__(self)
        self.list = []

    def append_list(self, item):
        self.list.append(item)
        print 'append list', self.list

    def run(self):
        while True:
            print 'list running', self.list
            import time
            time.sleep(2)
a = A()
a.start()

i = 0
while True:
    i+=1
    import time
    time.sleep(2)
    a.append_list(i)
  • 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-31T03:31:28+00:00Added an answer on May 31, 2026 at 3:31 am

    the fact that you are calling a function on the process class, doesn’t mean it runs in the sub process.

    when you create your A object, the list is in the main process. when you run start() on it, the list gets copied to the child process (well, not exactly, but let’s assume it for simplicity). then when the parent process calls the function, you are appending to a list that’s only in the memory of the parent process. the one in the child, even though it has the same name, now belongs to a different python process.

    If you want to share state between processes, you need to use shared memory objects, or queue objects. see here:

    http://docs.python.org/library/multiprocessing.html#sharing-state-between-processes

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

Sidebar

Related Questions

Suppose you have output like this: Word1 Word2 Word3 Word4 Where the number of
I have a SQL Server 2005 output like this: Date | Result | Sum
I'm trying something like this Output.py print Hello Input.py greeting = raw_input(Give me the
Often when writing PHP I'll have it output some HTML like this - echo
The output of /proc/net/dev on Linux looks like this: Inter-| Receive | Transmit face
I'm building a blog that should parse bbcode tags like this: Input: <youtube=http://www.youtube.com/watch?v=VIDEO_ID&feature=channel> Output:
I recently used the <<- operator to output a multi-line string, like this: <<-form
This is my my result html Output http://img2.pict.com/fc/c7/94/3241379/0/20100328195141.png And html of it is like
I have field like a_b_c_d I want as the output a b c_d, this
In this C# code snippet, DateTime.Now.Month.ToString() returns 7 as output. I would like to

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.