Why my modification of source file doesn't take effect when debugging?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sandorf

    Why my modification of source file doesn't take effect when debugging?

    I'm using the Windows version of Python and IDLE. When I debug my .py
    file, my modification to the .py file does not seem to take effect
    unless I restart IDLE. Saving the file and re-importing it doesn't help

    either. Where's the problem?

    Thanks.

  • Jeremy Jones

    #2
    Re: Why my modification of source file doesn't take effect whendebugging?

    sandorf wrote:
    [color=blue]
    >I'm using the Windows version of Python and IDLE. When I debug my .py
    >file, my modification to the .py file does not seem to take effect
    >unless I restart IDLE. Saving the file and re-importing it doesn't help
    >
    >either. Where's the problem?
    >
    >Thanks.
    >
    >
    >[/color]
    No problem. Just reload() it.


    - jmj

    Comment

    • infidel

      #3
      Re: Why my modification of source file doesn't take effect when debugging?

      > I'm using the Windows version of Python and IDLE. When I debug my .py[color=blue]
      > file, my modification to the .py file does not seem to take effect
      > unless I restart IDLE. Saving the file and re-importing it doesn't help
      > either. Where's the problem?[/color]

      "import" only reads the file the first time it's called. Every import
      call after that looks up the module in memory. This is to prevent
      circular dependencies between modules from creating infinite loops.
      You need to use the reload() function:
      [color=blue][color=green][color=darkred]
      >>> import foo[/color][/color][/color]

      #change the contents of foo
      [color=blue][color=green][color=darkred]
      >>> foo = reload(foo)[/color][/color][/color]

      Comment

      • Christophe

        #4
        Re: Why my modification of source file doesn't take effect when debugging?

        infidel a écrit :[color=blue][color=green]
        >>I'm using the Windows version of Python and IDLE. When I debug my .py
        >>file, my modification to the .py file does not seem to take effect
        >>unless I restart IDLE. Saving the file and re-importing it doesn't help
        >>either. Where's the problem?[/color]
        >
        >
        > "import" only reads the file the first time it's called. Every import
        > call after that looks up the module in memory. This is to prevent
        > circular dependencies between modules from creating infinite loops.
        > You need to use the reload() function:[/color]

        As a matter of fact, it would help a lot if that stupid behaviour of
        Idle was dropped. I'm sure I'm not the only one who lost lots of time
        because of that bug. Yes I call it a bug.

        Comment

        • Scott David Daniels

          #5
          Re: Why my modification of source file doesn't take effect when debugging?

          Christophe wrote:[color=blue]
          > infidel a écrit :[color=green][color=darkred]
          >>> I'm using the Windows version of Python and IDLE. When I debug my .py
          >>> file, my modification to the .py file does not seem to take effect
          >>> unless I restart IDLE. Saving the file and re-importing it doesn't help
          >>> either. Where's the problem?[/color]
          >>
          >> "import" only reads the file the first time it's called. Every import
          >> call after that looks up the module in memory. This is to prevent
          >> circular dependencies between modules from creating infinite loops.
          >> You need to use the reload() function:[/color]
          >
          > As a matter of fact, it would help a lot if that stupid behaviour of
          > Idle was dropped. I'm sure I'm not the only one who lost lots of time
          > because of that bug. Yes I call it a bug.[/color]
          You are mistaken if you think this is an Idle behavior; it is a Python
          behavior that speeds the execution of large systems.

          --Scott David Daniels
          scott.daniels@a cm.org

          Comment

          • Fredrik Lundh

            #6
            Re: Why my modification of source file doesn't take effectwhendebug ging?

            Christophe wrote:
            [color=blue][color=green]
            > > "import" only reads the file the first time it's called. Every import
            > > call after that looks up the module in memory. This is to prevent
            > > circular dependencies between modules from creating infinite loops.
            > > You need to use the reload() function:[/color]
            >
            > As a matter of fact, it would help a lot if that stupid behaviour of
            > Idle was dropped. I'm sure I'm not the only one who lost lots of time
            > because of that bug. Yes I call it a bug.[/color]

            in the version of IDLE I have on this machine, if I modify my script and
            run it again (using F5), things work exactly as expected.

            if I modify my script and import it into a clean shell (ctrl-F6), things work
            exactly as expected.

            the only way to get the "buggy" behaviour you're describing is to attempt
            to run your program by importing it as a module more than once into an
            existing python shell process. in that case, import works in the same way
            as it always works.

            after all, "import" isn't designed to run programs, it's designed to import
            modules. if you want to run stuff in IDLE, why not just use the "run"
            command ?

            </F>



            Comment

            • Christophe

              #7
              Re: Why my modification of source file doesn't take effect whendebugging?

              Fredrik Lundh a écrit :[color=blue]
              > Christophe wrote:
              >
              >[color=green][color=darkred]
              >>>"import" only reads the file the first time it's called. Every import
              >>>call after that looks up the module in memory. This is to prevent
              >>>circular dependencies between modules from creating infinite loops.
              >>>You need to use the reload() function:[/color]
              >>
              >>As a matter of fact, it would help a lot if that stupid behaviour of
              >>Idle was dropped. I'm sure I'm not the only one who lost lots of time
              >>because of that bug. Yes I call it a bug.[/color]
              >
              >
              > in the version of IDLE I have on this machine, if I modify my script and
              > run it again (using F5), things work exactly as expected.
              >
              > if I modify my script and import it into a clean shell (ctrl-F6), things work
              > exactly as expected.
              >
              > the only way to get the "buggy" behaviour you're describing is to attempt
              > to run your program by importing it as a module more than once into an
              > existing python shell process. in that case, import works in the same way
              > as it always works.
              >
              > after all, "import" isn't designed to run programs, it's designed to import
              > modules. if you want to run stuff in IDLE, why not just use the "run"
              > command ?[/color]

              F5 is designed to run the current open file. Sane people won't assume
              that pressing twice the F5 key will yield different. Sane people will
              assume that when you edit file1.py and press F5, it reparses the file,
              but when you edit file2.py and press F5 with file1.py it won't work. Why
              make it different ? Why make is so that I have to select the shell
              window, press CTRL+F6, select the file1.py and press F5 just so that it
              works as expected ?

              Idle is ok when you edit a single .py file. As soon as I need to edit 2
              ..py files with one using the other, I'm glad I have other editors which
              spanw a clean shell each time I run the current file.

              Comment

              • Fredrik Lundh

                #8
                Re: Why my modification of source file doesn't takeeffectwhend ebugging?

                "Christophe " wrote:
                [color=blue]
                > F5 is designed to run the current open file. Sane people won't assume
                > that pressing twice the F5 key will yield different. Sane people will
                > assume that when you edit file1.py and press F5, it reparses the file,
                > but when you edit file2.py and press F5 with file1.py it won't work. Why
                > make it different ? Why make is so that I have to select the shell
                > window, press CTRL+F6, select the file1.py and press F5 just so that it
                > works as expected ?[/color]

                I'm not sure I follow here: in the version of IDLE I have here, pressing
                F5 will save the current file and run it. If you've edit other parts of the
                application, you have to save those files (Control-S) and switch to the
                main script before pressing F5, but that's only what you'd expect from
                a "run this module" command.

                (being able to bind F5 to a specific script might be practical, of course,
                but I'm don't think that's what you're complaining about. or is it?)
                [color=blue]
                > Idle is ok when you edit a single .py file. As soon as I need to edit 2
                > .py files with one using the other, I'm glad I have other editors which
                > spanw a clean shell each time I run the current file.[/color]

                In the version of IDLE I have, that's exactly what happens (that's what
                the RESTART lines are all about).

                Is there some secret setting somewhere that I've accidentally managed
                to switch on or off to get this behaviour?

                </F>



                Comment

                • Christophe

                  #9
                  Re: Why my modification of source file doesn't take effectwhendebug ging?

                  Fredrik Lundh a écrit :[color=blue]
                  > "Christophe " wrote:
                  >
                  >[color=green]
                  >>F5 is designed to run the current open file. Sane people won't assume
                  >>that pressing twice the F5 key will yield different. Sane people will
                  >>assume that when you edit file1.py and press F5, it reparses the file,
                  >>but when you edit file2.py and press F5 with file1.py it won't work. Why
                  >>make it different ? Why make is so that I have to select the shell
                  >>window, press CTRL+F6, select the file1.py and press F5 just so that it
                  >>works as expected ?[/color]
                  >
                  >
                  > I'm not sure I follow here: in the version of IDLE I have here, pressing
                  > F5 will save the current file and run it. If you've edit other parts of the
                  > application, you have to save those files (Control-S) and switch to the
                  > main script before pressing F5, but that's only what you'd expect from
                  > a "run this module" command.
                  >
                  > (being able to bind F5 to a specific script might be practical, of course,
                  > but I'm don't think that's what you're complaining about. or is it?)
                  >
                  >[color=green]
                  >>Idle is ok when you edit a single .py file. As soon as I need to edit 2
                  >>.py files with one using the other, I'm glad I have other editors which
                  >>spanw a clean shell each time I run the current file.[/color]
                  >
                  >
                  > In the version of IDLE I have, that's exactly what happens (that's what
                  > the RESTART lines are all about).
                  >
                  > Is there some secret setting somewhere that I've accidentally managed
                  > to switch on or off to get this behaviour?[/color]

                  What I remember ( but maybe it was changed in recent Idle versions ) was
                  that when your project has a main.py which imports a module.py, when you
                  run your project once, any later changes you make in module.py won't be
                  taken into account.

                  Comment

                  • Dave Hansen

                    #10
                    Re: Why my modification of source file doesn't take effect when debugging?

                    On Fri, 02 Dec 2005 18:04:15 +0100 in comp.lang.pytho n, Christophe
                    <chris.cavalari a@free.fr> wrote:
                    [color=blue]
                    >infidel a écrit :[color=green][color=darkred]
                    >>>I'm using the Windows version of Python and IDLE. When I debug my .py
                    >>>file, my modification to the .py file does not seem to take effect
                    >>>unless I restart IDLE. Saving the file and re-importing it doesn't help
                    >>>either. Where's the problem?[/color]
                    >>
                    >>
                    >> "import" only reads the file the first time it's called. Every import
                    >> call after that looks up the module in memory. This is to prevent
                    >> circular dependencies between modules from creating infinite loops.
                    >> You need to use the reload() function:[/color]
                    >
                    >As a matter of fact, it would help a lot if that stupid behaviour of
                    >Idle was dropped. I'm sure I'm not the only one who lost lots of time
                    >because of that bug. Yes I call it a bug.[/color]

                    But, if you are editing a Python Module in Idle, and press F5 to run
                    the module, the interpreter is restarted for you. So what's the
                    problem?

                    I would consider it a far greater problem if Idle _didn't_ do that --
                    it could mean you module worked when you were debuggining it because
                    of some initialization that doesn't get performed in a clean start.

                    Regards,
                    -=Dave

                    --
                    Change is inevitable, progress is not.

                    Comment

                    • Christophe

                      #11
                      Re: Why my modification of source file doesn't take effect when debugging?

                      Dave Hansen a écrit :[color=blue]
                      > On Fri, 02 Dec 2005 18:04:15 +0100 in comp.lang.pytho n, Christophe
                      > <chris.cavalari a@free.fr> wrote:
                      >
                      >[color=green]
                      >>infidel a écrit :
                      >>[color=darkred]
                      >>>>I'm using the Windows version of Python and IDLE. When I debug my .py
                      >>>>file, my modification to the .py file does not seem to take effect
                      >>>>unless I restart IDLE. Saving the file and re-importing it doesn't help
                      >>>>either. Where's the problem?
                      >>>
                      >>>
                      >>>"import" only reads the file the first time it's called. Every import
                      >>>call after that looks up the module in memory. This is to prevent
                      >>>circular dependencies between modules from creating infinite loops.
                      >>>You need to use the reload() function:[/color]
                      >>
                      >>As a matter of fact, it would help a lot if that stupid behaviour of
                      >>Idle was dropped. I'm sure I'm not the only one who lost lots of time
                      >>because of that bug. Yes I call it a bug.[/color]
                      >
                      >
                      > But, if you are editing a Python Module in Idle, and press F5 to run
                      > the module, the interpreter is restarted for you. So what's the
                      > problem?
                      >
                      > I would consider it a far greater problem if Idle _didn't_ do that --
                      > it could mean you module worked when you were debuggining it because
                      > of some initialization that doesn't get performed in a clean start.
                      >
                      > Regards,
                      > -=Dave
                      >[/color]

                      Well, I'm happy to see that Idle now restarts the interpreter by default
                      when you press F5. I guess I might consider using it again after all
                      that time :)

                      Comment

                      Working...