0

I'm puzzled why this crashes. I can paste these two lines into a python shell and reliably get a segfault and be kicked out of the Python session:

from PyQt5.QtCore import QDate
QDate(2011, 1, 2).daysTo(QDate(2012, 1, 1))

Adding try/except won't catch anything.

Versions I'm using:

Python 3.10.6 (main, Aug 3 2022, 17:39:45) [GCC 12.1.1 20220730] on linux

from PyQt5.QtCore import QT_VERSION_STR
from PyQt5.Qt import PYQT_VERSION_STR
print(QT_VERSION_STR)              # 5.15.4
print(PYQT_VERSION_STR)            # 5.15.7
musicamante
  • 41,230
  • 6
  • 33
  • 58
DarenW
  • 16,549
  • 7
  • 63
  • 102
  • 1
    I cannot reproduce this. Are you sure you're not running the python shell in some env dir or path that has a PyQt5 subfolder (like stub hints)? Can you try running it in a completely blank directory? – musicamante Oct 05 '22 at 01:31
  • I make a directory ~/temp/crashy/ and opened a terminal in there. It worked, no sefault! Pasting manually to a python prompt, or a script with a shebang (need to add print(), of course). But there's nothing odd in the directory I'm doing the main work in. It's a tiny demo program, just a few .py files, no tools used to build an initial project, just a simple manually run .py script. I deleted __pycache__ just to see, but no it still crashes. – DarenW Oct 05 '22 at 02:57
  • Oh wait, there *is* something funny here in this work directory - I stupidly named one of my scripts "datetime.py". Though I'm not importing python's datetime module, I can see how confusion may come about. – DarenW Oct 05 '22 at 03:00

1 Answers1

0

Solved! The script I'm running was named datetime.py in the directory. Bad idea, even if I'm only using the PyQt's date and time stuff. It's probably pulling in Python's datetime module behind the scenes.

Changing the name to "trydatetime.py" or "timedate.py" made the problem go away.

DarenW
  • 16,549
  • 7
  • 63
  • 102
  • 1
    I cannot check the PyQt sources right now, but I know for a fact that PyQt *does* use the `datetime` module for the helper functions `toPyDateTime()` (for QDateTime), `toPyDate()` (QDate) and `toPyTime()` (QTime). While it's true that PyQt should *technically* be more careful about importing the datetime module directly from the SL, it's also true that naming a script as a built-in module is certainly not a good idea ;-) – musicamante Oct 05 '22 at 03:37