How to keep the session alive?

When there are no interactive operations on JupyterLab notebook or terminal, after a while (not sure how long exactly), the session is closed and often see errors about JSON format, directory not found, and your server is not running as such.

I tried to run one while looping in the notebook (sleep every 5 seconds) and it kept running for 32 hours, but finally, the session still expired.

So, any known solution to keep the session alive?

The reason is that I need to run some logic in a notebook or terminal ipython for a long time to handle a huge dataset.

If 32 hours is not sufficient, then more traditional routes of executing long-running computations is in order. You can set up screen or tmux (or modern equivalent to attach and detach your running process on the command line with ipython as you reference. I will add though that traditionally a pure python approach will be faster than ipython in most cases.

Hopefully in looking into this you’ve seen discussions that Jupyter notebook isn’t well suited to what you are trying to do. If not, see here, here, and here under the ‘Jupyter Notebook’ section.