Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dependency between "Session/line number was not unique in database." error and Python code

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.

like image 554
abukaj Avatar asked May 16 '18 11:05

abukaj


1 Answers

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.

like image 187
abukaj Avatar answered Sep 19 '22 13:09

abukaj