Message364596
Hi Tim,
Thank you for clearing that up.
I ran the same code in 2.7 and 3.7 on Windows, Its showing the same error.
Yes, Its running in Linux-y systems. It depends on OS.
Regards,
Bharat
On Thu, Mar 19, 2020 at 2:25 AM Tim Peters <report@bugs.python.org> wrote:
>
> Tim Peters <tim@python.org> added the comment:
>
> u1 is a global _only_ in a process that runs `function()`, which declares
> u1 global and assigns it a value. You have no sane expectation that a
> worker process (none of which run `function()`) will know anything about it.
>
> Are you sure you're running 2.7 and 3.7 on the same machine? It's
> impossible that this code ever "worked" under Windows, but it might under
> Linux-y systems, which use `fork()` to create worker processes.
>
> The traceback you showed was obviously run under Windows. Under Python
> 2.7.11 on Windows, I get the same kind of error:
>
> NameError: global name 'u1' is not defined
>
> This is the code:
>
> from multiprocessing import Pool
> import traceback
>
> class Utils:
> def __init__(self):
> self.count = 10
>
> def function():
> global u1
> u1 = Utils()
> l1 = range(3)
> process_pool = Pool(1)
> try:
> process_pool.map(add, l1, 1)
> process_pool.close()
> process_pool.join()
> except Exception as e:
> process_pool.terminate()
> process_pool.join()
> print(traceback.format_exc())
> print(e)
>
> def add(num):
> total = num + u1.count
> print(total)
>
> if __name__ == "__main__":
> function()
>
> ----------
> nosy: +tim.peters
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue40005>
> _______________________________________
> |
|
Date |
User |
Action |
Args |
2020-03-19 06:51:53 | Bharatsolanki | set | recipients:
+ Bharatsolanki, tim.peters, eric.smith |
2020-03-19 06:51:53 | Bharatsolanki | link | issue40005 messages |
2020-03-19 06:51:53 | Bharatsolanki | create | |
|