Function changes won't apply without restart

Hello there! I am using atom for writing python and I have encountered the following problem. Supposing that I am using a function which I have written in a separate .py file and calling it inside my script, when I make changes into that function and save it, changes won’t occur after running my script. Instead I have to restart atom so that the changes can apply. Is this sth like a bug?

How are you running your script?

I am running my code with the Hydrogen package.

Does it work without restarting Atom when you run using a different method, such as the script package or the command line?

Yes. I just tested with script and it works pretty fine. I am just wondering why this happens with Hydrogen. I am using Hydrogen because it’s interactive.

What do you mean by “won’t be applied” then? With Hydrogen, you will need to run the function itself, and rerun anything that calls it that you want to have updated.

It means that if I change the function from let’s say return(x+2) to return(x+5) and save it, then when I call it in my script it won’t update unless I restart Atom. This is only the case when running the script with Hydrogen.

What do you mean by save it? You need to execute it again with Hydrogen for it to be updated.

I know. It just doesn’t work…

Any help guys? I really would like this to work with Hydrogen as well…

I have nothing more to add; “doesn’t work” is literally nothing to go off.

For what it’s worth, I installed Hydrogen and tried it just now. It worked exactly as expected with the following

def mult(arg): # line 1
    return 2 * arg

mult(2) # line 5
  • Executing line 1 and then line 5 shows 4 as the result.
  • Editing mult to be 3 * arg and then running line 1 and then line 5 shows 6 as the result.

Well it does not show the correct result when the function mult is on a seperate file. Unless I restart Atom. That’s my point.

Well, since the problem is confined to an interaction with Hydrogen, and nobody has joined this thread with any ideas, you may be better off asking the developers of Hydrogen for insight at its repository. There may even be an issue already that matches what you’re dealing with.

Sorry, I missed the separate file part.

In that case, it’s probably just caching the import. I found this article after a google search


Thanks!!! It seems that one has to import importlib and then do importlib.reload(nameofthefunction). It works like this!

1 Like