17

For some time I am getting the following error (warning?):

ERROR! Session/line number was not unique in database. History logging moved to new session

when working with Jupyter notebook (<XXXX> is a number, e.g. 9149). As the same error has been reported for Spyder (Spyder's Warning: "Session/line number not unique in database") my guess is that there is some problem with the IPython kernel logging.

The question is: may there be any relation between running my code and the error?

Is it likely the error is caused by my code? I touch IPython API as following:

import IPython 

def beep():
    Python.display.display(IPython.display.Audio(url="http://www.w3schools.com/html/horse.ogg", autoplay=True))

def play_sound(self, etype, value, tb, tb_offset=None):
    self.showtraceback((etype, value, tb), tb_offset=tb_offset)
    beep()

get_ipython().set_custom_exc((Exception,), play_sound)

I use the beep() function in my code. I also work with large data which results in MemoryError exceptions.

And more importantly, may the error affect my code behaviour (given I do not try to access the logs)?

[EDIT] It seems the issue is different than Spyder's Warning: "Session/line number not unique in database" as I am able to reproduce it with Jupyter Notebook but not with Spyder.

8
  • What exactly are you doing here? And I see some syntax issue around the beep function? May 18, 2018 at 16:03
  • @TarunLalwani Defining a function and a hook to play a sound of horse neighing after my calculations are either completed or an unhandled exception is raised. I am 100% sure there is no SyntaxError.
    – abukaj
    May 18, 2018 at 16:09
  • Yes, my bad didn't scroll horizontally. Two things. What happens when you removing logging? Also if you move IPython.display.Audio(url="http://www.w3schools.com/html/horse.ogg", autoplay=True) inside the function and keep default value as None. Check if None then initiate the sound May 18, 2018 at 16:12
  • @TarunLalwani I have removed playing with the logging module and have rewritten the beep() function - the warning is still present.
    – abukaj
    May 21, 2018 at 13:15
  • This sounds like your IPython history database got corrupted. Try cleaning it up (i.e. remove/temporary relocate your $IPYTHONDIR/profile_default/history.sqlite file) and see if it still happens.
    – zwer
    May 21, 2018 at 13:23

3 Answers 3

8

It is only a partial answer - the bounty is still eligible.

The error does depend on my code - at least when there is SyntaxError.

I have reproduced it with three following cells.

In [31]: print(1)
         1

In [31]: print 2
           File "<ipython-input-32-9d8034018fb9>", line 1
             print 2
                   ^
         SyntaxError: Missing parentheses in call to 'print'

In [32]: print(2)
         2
         ERROR! Session/line number was not unique in database. History logging moved to new session 7

As you can see the line counter has been not increased in the second cell (with syntax issues).

Inspired by @zwer's comment, I have queried the $HOME/.ipython/profile_default/history.sqlite database:

sqlite> select session, line, source from history where line > 30;
6|31|print(1)
6|32|print 2
7|32|print(2)

It is clear that the line counter for the second cell has been increased in the database, but not in the notebook.

Thus when the third cell has been executed successfully, the notebook attempted to store its source with the same line, which offended the PRIMARY KEY constraint:

sqlite> .schema history
CREATE TABLE history
                (session integer, line integer, source text, source_raw text,
                PRIMARY KEY (session, line));

As a result, a failsafe has been triggered which issued the warning and created a new session.

I guess the issue is not affecting my code behaviour, however I miss a credible source for such statement.

1
  • It happened the same for me. The reason of my problem was that my script was encrypted in a strange format. I just had to change it to UTF-8 Feb 11, 2022 at 15:29
1

I experienced the same error when I was trying to run some asyncio code in a jupyter notebook. The gist was like this (might make sense to those familiar with asyncio)

cell #1 
output = loop.run_until_complete(future)

cell #2
print(output)

Run both cells together, and I would get OP's error. Merge the cells together like so, and it ran cleanly

cell #1 
output = loop.run_until_complete(future)
print(output)
-1

This problem arises in the Jupyter Notebook cells when the cells have the same line number.
What you can do - if you are in Jupyter Notebook - is just restart the kernel.
The error will be solved.

2
  • 1
    The problem is that after restart the state is lost. And the state may be worth several days of computation.
    – abukaj
    Apr 12, 2020 at 19:31
  • 4
    @abukaj Dude! Don't store several days of computation in RAM. Serialize it somehow! Pickle/json/csv/anything..
    – elgehelge
    Feb 25, 2022 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.