[issue40005] Getting different result in python 2.7 and 3.7.
Bharat Solanki added the comment: 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 wrote: > > Tim Peters 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 > <https://bugs.python.org/issue40005> > ___ > -- ___ Python tracker <https://bugs.python.org/issue40005> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40005] Getting different result in python 2.7 and 3.7.
Bharat Solanki added the comment: u1 is global variable. So I can use it any where. Rigth! Thanks Bharat On Thu, Mar 19, 2020, 2:09 AM Bharat Solanki wrote: > > Bharat Solanki added the comment: > > When you run this test.py in 2.7. you will get output (10 11 20), But in > 3.7, Its getting failed. Its showing below error: > > "Traceback (most recent call last): > File "test.py", line 14, in function > process_pool.map(add, l1, 1) > File "C:\Users\Bharat Solanki\Anaconda3\lib\multiprocessing\pool.py", > line 268, in map > return self._map_async(func, iterable, mapstar, chunksize).get() > File "C:\Users\Bharat Solanki\Anaconda3\lib\multiprocessing\pool.py", > line 657, in get > raise self._value > NameError: name 'u1' is not defined" > > Please let me know if you need any other information. > > Thanks > Bharat > > -- > Added file: https://bugs.python.org/file48979/test.py > > ___ > Python tracker > <https://bugs.python.org/issue40005> > ___ > -- ___ Python tracker <https://bugs.python.org/issue40005> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40005] Getting different result in python 2.7 and 3.7.
Bharat Solanki added the comment: When you run this test.py in 2.7. you will get output (10 11 20), But in 3.7, Its getting failed. Its showing below error: "Traceback (most recent call last): File "test.py", line 14, in function process_pool.map(add, l1, 1) File "C:\Users\Bharat Solanki\Anaconda3\lib\multiprocessing\pool.py", line 268, in map return self._map_async(func, iterable, mapstar, chunksize).get() File "C:\Users\Bharat Solanki\Anaconda3\lib\multiprocessing\pool.py", line 657, in get raise self._value NameError: name 'u1' is not defined" Please let me know if you need any other information. Thanks Bharat -- Added file: https://bugs.python.org/file48979/test.py ___ Python tracker <https://bugs.python.org/issue40005> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue40005] Getting different result in python 2.7 and 3.7.
New submission from Bharat Solanki : Hi Team, Below code is giving different result in python 2.7 and 3.7 version. Code is running fine when i am using 2.7 but in 3.7, it is showing error. 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() Could you please help me on this how can it run in 3.7 version. Thanks, Bharat -- components: 2to3 (2.x to 3.x conversion tool) messages: 364559 nosy: Bharatsolanki priority: normal severity: normal status: open title: Getting different result in python 2.7 and 3.7. type: compile error versions: Python 2.7 ___ Python tracker <https://bugs.python.org/issue40005> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com