[issue20703] RuntimeError caused by lazy imports in pdb

2021-08-03 Thread Irit Katriel
Irit Katriel added the comment: Closing as this is not a problem with pdb, it's a general problem with iterating sys.modules while doing things that can cause imports. -- resolution: -> wont fix stage: patch review -> resolved status: open -> closed

[issue20703] RuntimeError caused by lazy imports in pdb

2021-08-03 Thread Irit Katriel
Irit Katriel added the comment: Can we make sys.modules automatically return an iterator that has a copy of its contents? Otherwise it's an odd API - it's iterable but we tell people not to iterate it. -- ___ Python tracker

[issue20703] RuntimeError caused by lazy imports in pdb

2021-08-03 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: My concern about importing readline at the top of the module is that importing readline has a side effect. The only module which imports it unconditionally at the top is rlcompleter. In all other places it is imported lazily. And importing readline ahead

[issue20703] RuntimeError caused by lazy imports in pdb

2021-08-02 Thread Irit Katriel
Irit Katriel added the comment: I think option 2 changes the current behaviour, because cmd.Cmd.cmdloop will import readline later, and the set_completer_delims() call would never happen even though readline is used. I'll update the patch to do option 1. --

[issue20703] RuntimeError caused by lazy imports in pdb

2021-08-02 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Having a side effect at import time is not good. It will interfere with programs which just import pdb, but not use it. There are two other options: 1. Import readline at top level, but call set_completer_delims() lazily. 2. Do not import readline at

[issue20703] RuntimeError caused by lazy imports in pdb

2021-07-31 Thread Irit Katriel
Irit Katriel added the comment: I agree with both Eric and Xavier - any library calling a function that modifies sys.modules will see this issue, but pdb should try not to modify program semantics like this. It's fixed if we move the readline import as Louie suggested (the _bootlocale

[issue20703] RuntimeError caused by lazy imports in pdb

2021-07-31 Thread Irit Katriel
Change by Irit Katriel : -- keywords: +patch nosy: +iritkatriel nosy_count: 5.0 -> 6.0 pull_requests: +26035 stage: -> patch review pull_request: https://github.com/python/cpython/pull/27520 ___ Python tracker

[issue20703] RuntimeError caused by lazy imports in pdb

2017-06-26 Thread Mark Lawrence
Changes by Mark Lawrence : -- nosy: -BreamoreBoy ___ Python tracker ___ ___

[issue20703] RuntimeError caused by lazy imports in pdb

2017-06-26 Thread Louie Lu
Changes by Louie Lu : -- versions: +Python 3.6, Python 3.7 -Python 3.4, Python 3.5 ___ Python tracker ___

[issue20703] RuntimeError caused by lazy imports in pdb

2017-06-26 Thread Louie Lu
Louie Lu added the comment: The lazy import cause by two modules, readline and _bootlocale. readline: in __init__ try: import readline readline.set_completer_delims(' \t\n`@#$%^&*()=+[{]}\\|;:\'",<>?') _bootlocale: in __init__ with open(os.path.join(envHome, '.pdbrc'))

[issue20703] RuntimeError caused by lazy imports in pdb

2015-02-27 Thread Xavier de Gaye
Xavier de Gaye added the comment: In that case the behavior you are seeing is correct, even if not obvious or even desirable. It will happen any time you are looping over sys.modules and call a function/method which has a function-scoped import statement for a module that hasn't been

[issue20703] RuntimeError caused by lazy imports in pdb

2015-02-26 Thread Eric Snow
Eric Snow added the comment: I haven't looked to closely but I'm guessing that pdb.set_trace() causes something to get imported (i.e. there's an import statement in a function body somewhere). Consequently sys.modules is updated (by that distant import statement) while you are iterating over

[issue20703] RuntimeError caused by lazy imports in pdb

2015-02-26 Thread Mark Lawrence
Mark Lawrence added the comment: My tests were done with a script from the command line, not an interactive prompt. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20703 ___

[issue20703] RuntimeError caused by lazy imports in pdb

2015-02-26 Thread Xavier de Gaye
Xavier de Gaye added the comment: I can reproduce this on Windows 8.1 with 3.4.3 but cannot do so with 3.5.0a1. I can still reproduce this on linux on today's tip: '3.5.0a1+ (default:7185a35fb293, Feb 26 2015, 11:27:11) \n[GCC 4.9.2 20150204 (prerelease)]'. Maybe you tried reproducing it

[issue20703] RuntimeError caused by lazy imports in pdb

2015-02-25 Thread Mark Lawrence
Mark Lawrence added the comment: I can reproduce this on Windows 8.1 with 3.4.3 but cannot do so with 3.5.0a1. -- nosy: +BreamoreBoy versions: +Python 3.5 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue20703

[issue20703] RuntimeError caused by lazy imports in pdb

2015-02-25 Thread Josh Rosenberg
Josh Rosenberg added the comment: Is this worth fixing? Delve into the innards and you get weird behaviors. If you really need to iterate sys.modules (the example clearly doesn't, but that doesn't mean no one would), you could just copy the parts you need beforehand to get a consistent view,

[issue20703] RuntimeError caused by lazy imports in pdb

2014-02-20 Thread Xavier de Gaye
New submission from Xavier de Gaye: Issuing the 'continue' pdb command with a lazy_import.py script as: # START of lazy_import.py import sys, pdb for m in sys.modules: if m == 'sys': pdb.set_trace() # END of lazy_import.py gives the following output: $ python lazy_import.py