M
M
MegaTort2021-11-21 03:09:21
Python
MegaTort, 2021-11-21 03:09:21

Why does id change with multiprocess Python?

I can't figure out why the id of a global variable changes in another process
Made a class to test multiprocessing
Declared a self.counter list
Created three get_1..get_3 methods that increase the length of this list. I did not use numbers, since they have their own IDs.
I made a progressbar method that should accept this changing list.
But for some reason it has the same self.counter has a different id, and when I change it in the get methods in the progressbar, it will not change, because the other id...
61998de782a63272873148.jpeg

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
galaxy, 2021-11-21
@galaxy

when i change it in get methods in progressbar it will not change because different id

id is not your problem. get() and progressbar() run from different processes (read at least on Wikipedia what it is). Processes have an independent address space each, and variables in different processes are not related to each other in any way.
Read how to share information between processes.
To the question about id: id is, roughly speaking, the address of the corresponding structure variable in memory (in CPython). Even if this address is the same in different processes, it does not mean anything, because process address spaces are independent and virtual.
On the other hand, the specific address depends on how memory was allocated when the process was started and executed. Multiprocessing starts a new process a little differently than you, so the addresses are different.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question