2

For an analysis application I'm trying to:

  1. Get a list of filenames from the user using PyQt4 QFileDialog
  2. Extract some data from each file
  3. Plot the aggregated data using pyplot

However, getting the filenames this way causes pyplot.show() to take a really, really long time. I've distilled the problem down to the following test case:

import matplotlib.pyplot as plt
from PyQt4 import QtCore, QtGui

app = QtGui.QApplication(None)

fd = QtGui.QFileDialog(None)
filenames = fd.getOpenFileNames(caption='Select Data Files')

plt.plot([1,2,3,4,5])
plt.show()

Note that I'm not even doing anything with the filenames here--just getting them.

Selecting a single file from the dialog results in a plot time of 10 seconds. Interestingly, the time required for show() to complete goes up roughly linearly with the number of files selected. For 10 files it takes about 67 seconds for the plot to show.

This isn't a big deal for plotting data from a handful of files, but when aggregating data from Monte Carlo simulations where there are thousands of files it can take literally hours for the plot to show. Telling matplotlib to use the Qt4Agg backend results in the same behavior.

If I comment out the call to getOpenFileNames the script will complete in under a second.

I'm running the following versions of the relevant packages (should be latest):

  • Python 2.7
  • matplotlib 1.3.1
  • python-sip 4.13.2-1
  • python-qt4 4.9.1-2ubuntu1
  • python-sip-dev 4.13.2-1
  • python-qt4-dev 4.9.1-2ubuntu1

I uninstalled sip, qt4 and reinstalled them--same issue. I've seen the issue accross two separate machines--both running 32-bit Ubuntu 12.04.

Any help would be much appreciated--I've wasted an embarrassing amount of time waiting for plots to show.


Updates:

  • The type and name of the files selected doesn't seem to matter.
  • Cancelling or exiting the file dialog box results in no delay and an immediate plot.
  • Running the script as sudo eliminates the issue; however, the file dialog looks different when I run as sudo and may be using a different gui backend that doesn't conflict with pyplot's use of PyQt, so may be a red herring.
  • The program doesn't hang in getOpenFileNames, it hangs on the next call that uses PyQt. Whether that's a plot or another file dialog doesn't seem to matter--the first file dialog blocks both.
  • Calling app.processEvents() after running the dialog doesn't help.
  • Using PySide in place of PyQt4 results in the same behavior.
  • Using getOpenFileName instead of getOpenFileNames results in the same behavior.
  • Running getOpenFileNames with the DontUseNativeDialog option works (no delay)
  • None of the other QFileDialog options have any effect (ShowDirsOnly, DontResolveSymlinks, DontConfirmOverwrite, ReadOnly, HideNameFilterDetails, DontUseSheet)
  • A web-search for "getOpenFileNames slow" gets a ton of hits reporting problems on all platforms and several different Qt versions. However, its not easily reproducible (I can't reproduce it myself on either Linux or WinXP), and I couldn't find any obvious solutions (I didn't look that hard, though). – ekhumoro Mar 18 '14 at 22:40
  • @ekhumoro Thanks, not being able to recreate is useful information. What versions of pyqt4 and matplotlib were you using on the Linux machine? What version of Linux? 32 or 64-bit? – user3434957 Mar 19 '14 at 13:48
  • ArchLinux 64-bit, WinXP 32-bit, Qt-4.8.5. The python stuff is unimportant, as this is mainly a Qt issue. I also don't think it's got anything to do with matplotlib. But it looks like you may have already found a workaround: don't use the native file-dialogs. – ekhumoro Mar 19 '14 at 19:10

0 Answers0