Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuntimeWarning: 'ipdb.__main__' found in sys.modules after import of package 'ipdb', but prior to execution of 'ipdb.__main__'; this may result in unpredictable behaviour warn(RuntimeWarning(msg)) #221

Open
alayamanas opened this issue Mar 6, 2021 · 4 comments

Comments

@alayamanas
Copy link

My command is : python -m ipdb test.py
and I got:

/root/.miniconda3/lib/python3.6/runpy.py:125: RuntimeWarning: 'ipdb.__main__' found in sys.modules after import of package 'ipdb', but prior to execution of 'ipdb.__main__'; this may result in unpredictable behaviour
  warn(RuntimeWarning(msg))

What does this mean and how do I fix it? Thank you!
ps: ipdb version 0.13.5

@mikez
Copy link

mikez commented Aug 13, 2021

@alayamanas If this is possible on your system, try running ipdb directly:

ipdb3 test.py

Since several others (over 1000 reported views) have run into this as well, it might be worth fixing.

Some background

  • In Python 3, when you run python -m it first imports the module (runs __init__.py) and then __main__.py directly.
  • There is no easy way to tell in __init__.py whether ipdb was run with the -m flag.

Two possible solutions

  1. Do as many other libraries: move most of the main logic into a new file, e.g. ipdb.py and import from there, both in __init__.py and also in __main__.py.
  2. Move most of the logic and main() function into __init__.py and import main from __main__.py.

What do you think @gotcha?

@gotcha
Copy link
Owner

gotcha commented Sep 9, 2021

@mikez would you point me to one of those libraries ? It woule help me understand point 2 in your proposal.

A PR would be even better 😉

@mikez
Copy link

mikez commented Sep 9, 2021

@gotcha The most important thing to understand is what python -m does in Python3 (see my above post). After that, it boils down to moving most lines from __main__.py to another file. Either to a new file (e.g. ipdb.py) or to __init__.py.

Hope that helps. For the solution (1) you can see most CLIs out there, for example flask or pip. The solution (2) I haven't seen in the wild I think, but it should work just as well. The important thing here is to understand what python -m does.

@gotcha
Copy link
Owner

gotcha commented Sep 10, 2021

@mikez Thanks for the clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants