Question

I have a program that's working fine, then I added this code for testing purposes:

class datetimeMock(datetime.datetime): 
    def utcnow():
        return datetime.datetime (2013, 12, 17, 12)

if __name__=="__main__":

    #testing:
    datetime.datetime = datetimeMock        

    # start processing ...

Now the program seems to be working fine, but I'm getting this error on exit:

Error in atexit._run_exitfuncs:                                                              
Traceback (most recent call last):                                                           
  File "C:\Python33\lib\site-packages\IPython\core\history.py", line 508, in end_session     
    len(self.input_hist_parsed)-1, self.session_number))                                     
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.               

Can anyone make sense of this error?

Was it helpful?

Solution

Replacing a builtin type is begging for trouble ;-) Try restoring datetime.datetime to its original value before your program exits. atexit is run when the program is shutting down (see the docs - it's a standard Python module). Presumably IPython is using sqlite3 when the program ends to store some history, and your bogus datetime.datetime class is confusing the heck out of it.

orig_datetime = datetime.datetime  # new
datetime.datetime = datetimeMock   # the same

try:
    # start processing
    ...
finally:
    datetime.datetime = orig_datetime

Or run your program from a vanilla shell, instead of via IPython.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top