Strange disassembly
>>> sys.version '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' >>> def chk(x): ... if not(0 < x < 10): raise Exception ... >>> dis.dis(chk) 2 0 LOAD_CONST 1 (0) 2 LOAD_FAST0 (x) 4 DUP_TOP 6 ROT_THREE 8 COMPARE_OP 0 (<) 10 POP_JUMP_IF_FALSE 11 (to 22) 12 LOAD_CONST 2 (10) 14 COMPARE_OP 0 (<) 16 POP_JUMP_IF_TRUE14 (to 28) 18 LOAD_GLOBAL 0 (Exception) 20 RAISE_VARARGS1 >> 22 POP_TOP 24 LOAD_GLOBAL 0 (Exception) 26 RAISE_VARARGS1 >> 28 LOAD_CONST 0 (None) 30 RETURN_VALUE >>> Why are there two separate bytecode blocks for the "raise Exception"? I'd have thought that the double condition would still be evaluated as one thing, or at least that the jump destinations for both the early-abort and the main evaluation should be the same. ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: How Do I Get A Bug In Multiprocessing Fixed?
On Fri, 18 Jun 2021 at 15:27, Michael Boom wrote: > The below issue is pretty serious and it is preventing me from using a > system I wrote on a larger scale. How do I get this bug fixed? Thanks. > https://bugs.python.org/issue43329 On Fri, 18 Jun 2021 at 06:07, Alexander Neilson wrote: > > I am very interested to note that a report filed in February hasn't had at > least one person take a brief look at it and post a note or set a status > like "needs more info" etc. > Personally I don't find that surprising. I just looked at the issue very quickly and I couldn't immediately tell if the problem was a bug in multiprocessing or a mistake in the code shown. Just figuring that out would take more than the very little time I was prepared to spend looking at it so I moved on. If the OP hopes that someone else will use their limited time to fix this issue for them then they should do what they can to make it as quick as possible for that other person. The first part of that is making clear why it should be considered a bug in the first place. Don't expect the reader to spend time deciphering your code to figure that out. If there is a bug in multiprocessing then the issue should be clearer about what it is or why it should be considered a bug. Which function is documented as doing something that apparently does not work in this case? Why should it be expected to work? -- Oscar -- https://mail.python.org/mailman/listinfo/python-list
Faker package
I'm trying to use the faker package to generate data to load in a sample postgres database so I can learn how to use tksheet and psycopg2. The 8.8.1 documentation shows output on a root shell prompt (#), not a python prompt (>>>). It also has a description of using faker from 'the command line', which I assume is the python shell, and I can't get it to work. I suppose that I can generate one name, address, etc. at a time and them copy and concatenate them into table data, but I thought that the faker package would do this all for me. Is there a tool that will let me generate the equivalent of a database row worth of data? That is, a set of strings of different types that can then be inserted into the testing database? Rich -- https://mail.python.org/mailman/listinfo/python-list
Re: How Do I Get A Bug In Multiprocessing Fixed?
On 6/17/2021 5:02 PM, Michael Boom wrote: The below issue is pretty serious and it is preventing me from using a system I wrote on a larger scale. How do I get this bug fixed? Thanks. https://bugs.python.org/issue43329 Reduce your code to the minimum needed to exhibit the problem. Then run it with 3.9.5 and 3.10.0b3. 3.8 only gets security fixes. To get attention, demonstrate that there is a problem with current versions. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Tkinter problem
Am 18.06.21 um 08:28 schrieb Liya Ann Sunny: I am using Colab. How could solve this problem. TclError: couldn't connect to display ":0.0" You're either not running an X server, or having problems to connect to it. Are you sure that Google Colab supports X11 at all? This link doesn't seem to support that idea: https://stackoverflow.com/questions/61168210/is-there-any-way-to-use-tkinter-with-google-colaboratory Christian -- https://mail.python.org/mailman/listinfo/python-list
Re: Strange disassembly
On 6/18/2021 6:04 AM, Chris Angelico wrote: sys.version '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' def chk(x): ... if not(0 < x < 10): raise Exception 0 < x < 10 == 0 < x and x < 10, except that 'x' is evaluated once. not(_) == (not 0 < x) or (not x < 10) [== x <= 0 or 10 <= x] dis.dis(chk) 2 0 LOAD_CONST 1 (0) 2 LOAD_FAST0 (x) stack = 0 x. Since compare will remove both, must duplicate x and move duplicate out of the way. 4 DUP_TOP 6 ROT_THREE stack = x 0 x 8 COMPARE_OP 0 (<) test 0 < x, remove both, leaving stack = x 10 POP_JUMP_IF_FALSE 11 (to 22) if false, not 0 12 LOAD_CONST 2 (10) 14 COMPARE_OP 0 (<) Raise exception if false, making not x < 10 true So if true, jump to normal exit at end. Stack is empty. 16 POP_JUMP_IF_TRUE14 (to 28) 18 LOAD_GLOBAL 0 (Exception) 20 RAISE_VARARGS > >> 22 POP_TOP Must first remove unneeded duplicate of x! 24 LOAD_GLOBAL 0 (Exception) 26 RAISE_VARARGS1 >> 28 LOAD_CONST 0 (None) 30 RETURN_VALUE Why are there two separate bytecode blocks for the "raise Exception"? Because one block must POP_TOP and other must not. I'd have thought that the double condition would still be evaluated as one thing, or at least that the jump destinations for both the early-abort and the main evaluation should be the same. To reuse the exception block with POP_TOP, could jump over it after the 2nd compare. > 14 COMPARE_OP 0 (<) > 16 POP_JUMP_IF_TRUE14 (to 28) 18 JUMP(to 24) 20 NOP (#to avoid renumbering) > >> 22 POP_TOP > 24 LOAD_GLOBAL 0 (Exception) > 26 RAISE_VARARGS1 For the simplest and fasted bytecode, write normal logic and let x be reloaded instead of duplicated and rotated. >>> import dis >>> def f(x): ... if x <= 0 or 10 <= x: raise Exception ... ... >>> dis.dis(f) 2 0 LOAD_FAST0 (x) 2 LOAD_CONST 1 (0) 4 COMPARE_OP 1 (<=) 6 POP_JUMP_IF_TRUE 8 (to 16) 8 LOAD_CONST 2 (10) 10 LOAD_FAST0 (x) 12 COMPARE_OP 1 (<=) 14 POP_JUMP_IF_FALSE 10 (to 20) >> 16 LOAD_GLOBAL 0 (Exception) 18 RAISE_VARARGS1 >> 20 LOAD_CONST 0 (None) 22 RETURN_VALUE >>> -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Re: Faker package
On 6/18/2021 6:24 PM, Rich Shepard wrote: I'm trying to use the faker package to generate data to load in a sample postgres database so I can learn how to use tksheet and psycopg2. The 8.8.1 documentation shows output on a root shell prompt (#), not a python prompt (>>>). It also has a description of using faker from 'the command line', which I assume is the python shell, and I can't get it to work. I suppose that I can generate one name, address, etc. at a time and them copy and concatenate them into table data, but I thought that the faker package would do this all for me. Is there a tool that will let me generate the equivalent of a database row worth of data? That is, a set of strings of different types that can then be inserted into the testing database? I would try using the 'given' function/decorator of hypothesis (on pypi) to generate random data that conforms to whatever specification. -- Terry Jan Reedy -- https://mail.python.org/mailman/listinfo/python-list
Tkinter problem
I am using Colab. How could solve this problem. import tkinter as Tk from tkinter import * import sys import os #create main window master = Tk() master.title("tester") master.geometry("300x100") #make a label for the window label1 = tkinter.Label(master, text='Hello') # Lay out label label1.pack() # Run forever! master.mainloop() The error shows that : in () 9 10 #create main window ---> 11 master = Tk() 12 master.title("tester") 13 master.geometry("300x100") /usr/lib/python3.7/tkinter/__init__.py in __init__(self, screenName, baseName, className, useTk, sync, use) 2021 baseName = baseName + ext 2022 interactive = 0 -> 2023 self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use) 2024 if useTk: 2025 self._loadtk() TclError: couldn't connect to display ":0.0" -- https://mail.python.org/mailman/listinfo/python-list
Re: Strange disassembly
On Sat, Jun 19, 2021 at 9:50 AM Terry Reedy wrote: > > Why are there two separate bytecode blocks for the "raise Exception"? > > Because one block must POP_TOP and other must not. > > > I'd have thought that the double condition would still be evaluated as > > one thing, or at least that the jump destinations for both the > > early-abort and the main evaluation should be the same. > > To reuse the exception block with POP_TOP, could jump over it after the > 2nd compare. Hmm, fair enough I guess. The compiler figured that it'd be faster to duplicate the executable code rather than have the jump. It made for a somewhat confusing disassembly, but I presume it's faster to run. > For the simplest and fasted bytecode, write normal logic and let x be > reloaded instead of duplicated and rotated. > > >>> import dis > >>> def f(x): > ... if x <= 0 or 10 <= x: raise Exception > ... > ... > >>> dis.dis(f) >2 0 LOAD_FAST0 (x) >2 LOAD_CONST 1 (0) >4 COMPARE_OP 1 (<=) >6 POP_JUMP_IF_TRUE 8 (to 16) >8 LOAD_CONST 2 (10) > 10 LOAD_FAST0 (x) > 12 COMPARE_OP 1 (<=) > 14 POP_JUMP_IF_FALSE 10 (to 20) > >> 16 LOAD_GLOBAL 0 (Exception) > 18 RAISE_VARARGS1 > >> 20 LOAD_CONST 0 (None) > 22 RETURN_VALUE > >>> > Makes sense. I'm not sure if this would actually run faster, but I can't really justify warping my code around the disassembly :) Thanks for the explanation. I guess I just assumed the interpreter would prefer a jump to the duplication, but that's a decision it's free to take! ChrisA -- https://mail.python.org/mailman/listinfo/python-list
Re: Faker package
On Fri, 18 Jun 2021, Terry Reedy wrote: I would try using the 'given' function/decorator of hypothesis (on pypi) to generate random data that conforms to whatever specification. Thank you, Terry. I'll do that. Regards, Rich -- https://mail.python.org/mailman/listinfo/python-list
Re: Faker package
On 2021-06-18 23:24, Rich Shepard wrote: I'm trying to use the faker package to generate data to load in a sample postgres database so I can learn how to use tksheet and psycopg2. The 8.8.1 documentation shows output on a root shell prompt (#), not a python prompt (>>>). It also has a description of using faker from 'the command line', which I assume is the python shell, and I can't get it to work. I suppose that I can generate one name, address, etc. at a time and them copy and concatenate them into table data, but I thought that the faker package would do this all for me. When it says "command line" it means the operating system's command line. If it's the Python shell , it'll say "Python shell" or "Python prompt. The "root shell prompt (#)" suggests to me that it's Linux, so if you're using Windows you'll need to use the equivalent for Windows. Is there a tool that will let me generate the equivalent of a database row worth of data? That is, a set of strings of different types that can then be inserted into the testing database? -- https://mail.python.org/mailman/listinfo/python-list
Re: Faker package
On Sat, 19 Jun 2021, MRAB wrote: When it says "command line" it means the operating system's command line. If it's the Python shell , it'll say "Python shell" or "Python prompt. MRAB, The root shell's (#) what I assumed. User shells (in bash, anyway) have $ as the prompt. Regardless, $ faker -o temp.out faker.names() -bash: syntax error near unexpected token `(' [rshepard@salmo ~]$ faker -o temp.out faker.names Traceback (most recent call last): File "/usr/bin/faker", line 8, in sys.exit(execute_from_command_line()) File "/usr/lib64/python3.7/site-packages/faker/cli.py", line 264, in execute_from_command_line command.execute() File "/usr/lib64/python3.7/site-packages/faker/cli.py", line 246, in execute includes=arguments.include, File "/usr/lib64/python3.7/site-packages/faker/cli.py", line 67, in print_doc provider_or_field], includes=includes) File "/usr/lib64/python3.7/site-packages/faker/proxy.py", line 63, in __init__ **config) File "/usr/lib64/python3.7/site-packages/faker/factory.py", line 56, in create prov_cls, lang_found = cls._get_provider_class(prov_name, locale) File "/usr/lib64/python3.7/site-packages/faker/factory.py", line 68, in _get_provider_class provider_class = cls._find_provider_class(provider, locale) File "/usr/lib64/python3.7/site-packages/faker/factory.py", line 90, in _find_provider_class provider_module = import_module(provider_path) File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 965, in _find_and_load_unlocked ModuleNotFoundError: No module named 'faker.names' [rshepard@salmo ~]$ It does not work from the bash command line as a user or as root. The "root shell prompt (#)" suggests to me that it's Linux, so if you're using Windows you'll need to use the equivalent for Windows. I don't do windows; defenestrated 24 years ago. Rich -- https://mail.python.org/mailman/listinfo/python-list
Re: Faker package
On 2021-06-19 02:51, Rich Shepard wrote: On Sat, 19 Jun 2021, MRAB wrote: When it says "command line" it means the operating system's command line. If it's the Python shell , it'll say "Python shell" or "Python prompt. MRAB, The root shell's (#) what I assumed. User shells (in bash, anyway) have $ as the prompt. Regardless, $ faker -o temp.out faker.names() -bash: syntax error near unexpected token `(' [rshepard@salmo ~]$ faker -o temp.out faker.names Traceback (most recent call last): File "/usr/bin/faker", line 8, in sys.exit(execute_from_command_line()) File "/usr/lib64/python3.7/site-packages/faker/cli.py", line 264, in execute_from_command_line command.execute() File "/usr/lib64/python3.7/site-packages/faker/cli.py", line 246, in execute includes=arguments.include, File "/usr/lib64/python3.7/site-packages/faker/cli.py", line 67, in print_doc provider_or_field], includes=includes) File "/usr/lib64/python3.7/site-packages/faker/proxy.py", line 63, in __init__ **config) File "/usr/lib64/python3.7/site-packages/faker/factory.py", line 56, in create prov_cls, lang_found = cls._get_provider_class(prov_name, locale) File "/usr/lib64/python3.7/site-packages/faker/factory.py", line 68, in _get_provider_class provider_class = cls._find_provider_class(provider, locale) File "/usr/lib64/python3.7/site-packages/faker/factory.py", line 90, in _find_provider_class provider_module = import_module(provider_path) File "/usr/lib64/python3.7/importlib/__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "", line 1006, in _gcd_import File "", line 983, in _find_and_load File "", line 965, in _find_and_load_unlocked ModuleNotFoundError: No module named 'faker.names' [rshepard@salmo ~]$ It does not work from the bash command line as a user or as root. The "root shell prompt (#)" suggests to me that it's Linux, so if you're using Windows you'll need to use the equivalent for Windows. I don't do windows; defenestrated 24 years ago. It looks like you're mixing some Python usage ("faker.names()") in with command line usage. Judging from the docs, I'd say you need something more like: $ faker -o temp.out name for 1 fake name or: $ faker -r=10 -o temp.out name for 10 fake names. -- https://mail.python.org/mailman/listinfo/python-list
Re: Strange disassembly
On 18/06/2021 11:04, Chris Angelico wrote: sys.version '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' def chk(x): ... if not(0 < x < 10): raise Exception ... dis.dis(chk) 2 0 LOAD_CONST 1 (0) 2 LOAD_FAST0 (x) 4 DUP_TOP 6 ROT_THREE 8 COMPARE_OP 0 (<) 10 POP_JUMP_IF_FALSE 11 (to 22) 12 LOAD_CONST 2 (10) 14 COMPARE_OP 0 (<) 16 POP_JUMP_IF_TRUE14 (to 28) 18 LOAD_GLOBAL 0 (Exception) 20 RAISE_VARARGS1 >> 22 POP_TOP 24 LOAD_GLOBAL 0 (Exception) 26 RAISE_VARARGS1 >> 28 LOAD_CONST 0 (None) 30 RETURN_VALUE Why are there two separate bytecode blocks for the "raise Exception"? I'd have thought that the double condition would still be evaluated as one thing, or at least that the jump destinations for both the early-abort and the main evaluation should be the same. ChrisA As an ornery human I could refactor this to avoid the code duplication as 2 0 LOAD_CONST 1 (0) 2 LOAD_FAST 0 (x) 4 DUP_TOP 6 ROT_THREE 8 COMPARE_OP 0 (<) 10 POP_JUMP_IF_TRUE 10 (to 18) 12 POP_TOP >> 14 LOAD_GLOBAL 0 (Exception) 16 RAISE_VARARGS 1 >> 18 LOAD_CONST 2 (10) 20 COMPARE_OP 0 (<) 22 POP_JUMP_IF_FALSE 21 (to 14) 24 LOAD_CONST 0 (None) 26 RETURN_VALUE >>> (there may be mistakes in this) but this is probably too much to expect of the compiler. Rob Cliffe -- https://mail.python.org/mailman/listinfo/python-list
Re: Strange disassembly
On Sat, Jun 19, 2021 at 4:16 PM Rob Cliffe via Python-list wrote: > > > > On 18/06/2021 11:04, Chris Angelico wrote: > sys.version > > '3.10.0b2+ (heads/3.10:33a7a24288, Jun 9 2021, 20:47:39) [GCC 8.3.0]' > def chk(x): > > ... if not(0 < x < 10): raise Exception > > ... > dis.dis(chk) > >2 0 LOAD_CONST 1 (0) > >2 LOAD_FAST0 (x) > >4 DUP_TOP > >6 ROT_THREE > >8 COMPARE_OP 0 (<) > > 10 POP_JUMP_IF_FALSE 11 (to 22) > > 12 LOAD_CONST 2 (10) > > 14 COMPARE_OP 0 (<) > > 16 POP_JUMP_IF_TRUE14 (to 28) > > 18 LOAD_GLOBAL 0 (Exception) > > 20 RAISE_VARARGS1 > > >> 22 POP_TOP > > 24 LOAD_GLOBAL 0 (Exception) > > 26 RAISE_VARARGS1 > > >> 28 LOAD_CONST 0 (None) > > 30 RETURN_VALUE > > Why are there two separate bytecode blocks for the "raise Exception"? > > I'd have thought that the double condition would still be evaluated as > > one thing, or at least that the jump destinations for both the > > early-abort and the main evaluation should be the same. > > > > ChrisA > As an ornery human I could refactor this to avoid the code duplication as > >2 0 LOAD_CONST 1 (0) >2 LOAD_FAST0 (x) >4 DUP_TOP >6 ROT_THREE >8 COMPARE_OP 0 (<) > 10 POP_JUMP_IF_TRUE10 (to 18) > 12 POP_TOP > >> 14 LOAD_GLOBAL 0 (Exception) > 16 RAISE_VARARGS1 > >> 18 LOAD_CONST 2 (10) > 20 COMPARE_OP 0 (<) > 22 POP_JUMP_IF_FALSE 21 (to 14) > 24 LOAD_CONST 0 (None) > 26 RETURN_VALUE > >>> > > (there may be mistakes in this) but this is probably too much to expect > of the compiler. Hmm, I think that depends too much on knowing that the raise won't return. That might be a neat optimization (effectively a form of dead code removal), but otherwise, the best you could do would be to also have it jump out after the raise. ChrisA -- https://mail.python.org/mailman/listinfo/python-list