Ticket #8351 (closed: fixed)

Opened 7 years ago

Last modified 5 years ago

IPython console freezes if trying to print a DateAndTime

Reported by: Andrei Savici Owned by: Russell Taylor
Priority: critical Milestone: Release 3.1
Component: Python Keywords: PatchCandidate
Cc: Blocked By:
Blocking: Tester: Andrei Savici

Description (last modified by Russell Taylor) (diff)

The simplest example to reproduce:

print DateAndTime(1)

Old description:

In MantidPlot, type in the ipython interpreter

w=Load('CNCS7860')
r=w.getRun()
p=r.getProperty('Speed4')
print p.firstTime()

The console freezes up

Change History

comment:1 Changed 7 years ago by Russell Taylor

This seems to be an IPython bug - try it in a standalone IPython qtconsole and you'll see the errors. You do get the prompt back in that case but it becomes useless.

comment:2 Changed 7 years ago by Russell Taylor

It seems to boil down to the str method on the DateAndTime export (in PythonInterface/mantid/kernel/src/Exports/DateAndTime.cpp) sending back the result of a call to boost::posix_time::to_iso_extended_string(). If you switch it to calling DateAndTime::toSimpleString instead of DateAndTime::toISO8601String then things are fine. Since it's returning a string in either case, IPython must be trying to do something clever when it thinks it's a date.

comment:3 Changed 7 years ago by Russell Taylor

  • Description modified (diff)
  • Summary changed from python freezes on TimeSeriesProperty to IPython console freezes if trying to print a DateAndTime

comment:4 Changed 7 years ago by Russell Taylor

  • Keywords PatchCandidate added

comment:5 Changed 7 years ago by Russell Taylor

Here's an even simpler way to demonstrate the problem, and one that's independent of Mantid so I can feed it back to the IPython people:

print '2013-11-05T16:36:22.100000002'

comment:6 Changed 7 years ago by Russell Taylor

comment:7 Changed 7 years ago by Russell Taylor

  • Status changed from new to inprogress

Re #8351. Append a space to the string representation.

This is to get around a bug in IPython 1.1. The space is added to the representation only on the python side, not the C++ side. I believe this will have minimal/zero real impact and avoids crashing the IPython console.

Changeset: 46205ee84f589acf250a6fe170f6f2cda5be0cc3

comment:8 Changed 7 years ago by Russell Taylor

Re #8351. Amend tests to account for the additional space.

Changeset: e96a6647aa4ea9cb33d82ffa0e1bcddd3015d2fe

comment:9 Changed 7 years ago by Russell Taylor

  • Status changed from inprogress to verify
  • Resolution set to fixed

This represents the minimal change that solves the problem. There has been some talk of converting things to be Python datetime objects on the Python side, but that's beyond the scope of this fix.

To test: Make sure that the scriptlets above can be run without bringing down the IPython console.

comment:10 Changed 7 years ago by Andrei Savici

  • Status changed from verify to verifying
  • Tester set to Andrei Savici

comment:11 Changed 7 years ago by Andrei Savici

  • Status changed from verifying to closed

Merge remote-tracking branch 'origin/bugfix/8351_ipython_datetime_error'

Full changeset: 72a3f99a0f67a71987ed66099ab913ff0c163b62

comment:12 Changed 7 years ago by Andrei Savici

Works. The time string can also be used to generate new time series properties (see comment ticket #8301)

comment:13 Changed 5 years ago by Stuart Campbell

This ticket has been transferred to github issue 9196

Note: See TracTickets for help on using tickets.