Hi,
I’m facing something that apparently does not seem very simple to solve. The fact is that I’m producing some code that can either go on a notebook() in IJupyter, or be pasted on an ASCII text file (with .jl extension), and be run on the REPL. The fact is that I would like to know if there is a simple way to get the name of the file being ran.
For exemple ‘croco.jl’ (REPL) or ‘dile.ipynb’ (notebook) from within the code…
Thanks a lot,
Ferran.
1 Like
@__FILE__
works for .jl file. Not sure what it does for notebooks.
Thanks for the info, I already tried that. However, n the notebook it simply says “”
It’s not so easy to get this information in the notebook — it’s not directly available to the IJulia kernel in the Jupyter protocol. See e.g.
opened 03:48PM - 05 Jan 17 UTC
closed 12:18PM - 06 Jan 17 UTC
Is there a way to figure out the current ipynb file from within iPython?
Usec… ase: I want to trigger simulations from within IPython. To keep everything documented, I want to copy the IPython notebook in the results folder, ideally from within IPython.
Searching the web with this issue showed, that there seems to be a lot of interest for such a feature, but the solutions presented on stackoverflow all seemed to be a bit hacky. Or is this already implemented?
opened 10:37PM - 26 Jan 16 UTC
Hi,
I've seen this type of question a lot:
http://stackoverflow.com/questions/2… 0050927/how-to-get-the-ipython-notebook-title-associated-with-the-currently-running-ipyt?rq=1
It makes sense to me that the kernel should not know what it's talking to from a design perspective.
However, I'm currently in the process of working through a Jupyter High Availability scenario. Our goal is to have two Jupyter instances running in two different VMs and switch them if one of those two VMs go down for some reason without losing the kernel state.
We have control over the kernels we are running (see https://github.com/jupyter-incubator/sparkmagic/blob/master/remotespark/wrapperkernel/sparkkernelbase.py), and we'd like to be able to tie some state (a session number) to a particular kernel instance.
It seems to me like I'd need some things to achieve this, but maybe you have better ideas:
- Fire some piece of code automatically every time a notebook starts: this could be the `__init__` method in my kernel or some other piece of code that is triggered every time a kernel gets started (some Javascript code in the notebook maybe? I know this wouldn't apply for other clients but it's a start).
- This previous bit of code that gets fired would need to always be run with the same ID to be able to identify the state it needs to reconstruct (i.e. it would need to know that for this particular kernel we had X particular state).
- Some persistent storage that both Jupyter instances could have access to.
I thought of a concrete implementation and I'd like to hear some feedback on it if possible:
There is a Notebook extension that reads some ID in the notebook's page DOM (I need help knowing what ID this would be: e.g. notebook name with relative paths from root folder included or a GUID in some hidden cell in the notebook file), which would then issue a request to the kernel with this ID to restore its state. The kernel would then take this ID and get the session ID from cloud storage. If the ID is embedded in Javascript, both Jupyter servers would need to trust the notebook from the get go.
Thanks for any help or pointers you may have!
(cc. @msftristew, @MohamedElKamhawy, @ellisonbg)