Python Forum
How to avoid reloading modules in python
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to avoid reloading modules in python
#1
I am getting the warning:
Error:
"reloaded modules: chromosome_length"
Chromosome_length is actually a function that I am calling in another *.py file via the following:

from chromosome_length import chromosome_length
So, three things:

1) Why does a reloaded module happen?

2) What are the problems/issues it can cause?

3) How to avoid this happening?

P.S. I know how to deactivate the warning message, but I also want to understand why this is happening and how I should avoid it.
Reply
#2
Unless you're doing something wacky with the importlib module, you can't reload modules.
What's the whole warning/error message? Is there a traceback?
Reply
#3
(May-04-2018, 08:26 PM)nilamo Wrote: Unless you're doing something wacky with the importlib module, you can't reload modules.
What's the whole warning/error message? Is there a traceback?

It's actually the warning that I mentioned only:

Error:
"reloaded modules: chromosome_length"
I can deactivate it using the following:

import warnings
warnings.filterwarnings("ignore", message="Reloaded modules: <chromosome_length>")
I just wonder why I am getting this warning and how it can cause issues in my program and how to avoid this (instead of filtering the warning indeed)
Reply
#4
I can't imagine it'd cause any issues in your code, unless you do it a lot (a LOT), and then it might slow your program down a bit.
I also can't imagine how that's happening without you purposefully reloading the module, though, as they're cached. So just importing it multiple times wouldn't cause a reload.
Reply
#5
(May-04-2018, 09:03 PM)nilamo Wrote: I can't imagine it'd cause any issues in your code, unless you do it a lot (a LOT), and then it might slow your program down a bit.
I also can't imagine how that's happening without you purposefully reloading the module, though, as they're cached. So just importing it multiple times wouldn't cause a reload.

Thanks! So I just found this option in spyder which says:

"User Module Reloader (UMR): UMR forces Python to reload modules which were imported when executing a file in a Python or IPython console with the runfile function."

And I deactivated it and now it works perfectly! Now my question is, why would somebody need this option?! Like why would I need to reload a module if it is already imported when I was executing the file?
Reply
#6
https://github.com/spyder-ide/spyder/blo...loader-umr Wrote:This behavior is sometimes unexpected when working with the Python interpreter in interactive mode, because one must either always restart the interpreter or remove manually the .pyc files to be sure that changes made in imported modules were taken into account.

So one reason, is so that you can use whatever file you're editing, within the interactive session. Without the reload, your changes wouldn't be available in the interactive session, as the original file was still cached.

Practically, I don't think it matters, as you're not going to be using it interactively once you're done, anyway.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to see the date of installation of python modules. newbieAuggie2019 4 1,663 Mar-31-2023, 12:40 PM
Last Post: newbieAuggie2019
  Python modules for accessing the configuration of relevant paths Imago 1 1,396 May-07-2022, 07:28 PM
Last Post: Larz60+
  Avoid third party functions to wrote my python code into system debug-log? mark 9 2,241 Apr-09-2022, 08:41 PM
Last Post: mark
  Flask: How to make this web page not reloading? Aguscao 0 1,347 Jun-12-2021, 07:40 AM
Last Post: Aguscao
  Python modules to extract data from a graph? bigmit37 5 22,510 Apr-09-2021, 02:15 PM
Last Post: TysonL
  Where to add own python modules in WinPython? HinterhaeltigesSchlaengelchen 1 2,306 Jan-21-2021, 07:45 PM
Last Post: snippsat
  Including modules in Python using sys.path.append JoeDainton123 1 2,935 Aug-24-2020, 04:51 AM
Last Post: millpond
  how to get PID's of linux commands executed through python modules? Manikandan_PS 4 3,079 Mar-12-2020, 07:16 AM
Last Post: Manikandan_PS
  python modules davy_yg 1 2,005 Sep-25-2019, 03:14 AM
Last Post: metulburr
  Sub: Python-3: Better Avoid Naming A Variable As list ? adt 9 4,061 Aug-29-2019, 08:15 AM
Last Post: adt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020