properly close HDF5 filles and percussions for opening. - #1237
properly close HDF5 filles and percussions for opening.#1237sergey-yaroslavtsev wants to merge 3 commits into
Conversation
| """ | ||
| sigFileUpdated = qt.pyqtSignal(object) | ||
| sigFileAppended = qt.pyqtSignal(object) | ||
| sigReadError = qt.pyqtSignal(object) |
| "if that does not help, close and open the file again.") | ||
| msg.exec() | ||
|
|
||
| qt.QTimer.singleShot(0, _show) |
There was a problem hiding this comment.
First time in PyMca we popup a dialog with qt.QTimer. I'm assuming this is a the UI stays responsive.
Is this the direction we will be taking for all new dialogs? Will be refactor all the existing dialogs to this pattern? Should be use a helper for this?
There was a problem hiding this comment.
crash should not appear
But here we pop-up an dialog ...
There was a problem hiding this comment.
qt.QTimer here is to make the order:
with: all "drawing" and "build" (the empty three appear - because of return 0) are finished before message
without: message appear after trying to open the file - after message is closed the "drawing" and "build" are finished.
I do not know if it is crucial in this case.
If user somehow manage to change smthg in main window while message is open - then closing error message can lead to a crush. But of course main window is blocked during this message so one can say it is protected...
Let me know what you think about it.
There was a problem hiding this comment.
QDialog (which QMessageBox inherits from) has a open non-blocking method, IMO it' worth trying to replace the blocking exec with it and so avoid the QTimer
There was a problem hiding this comment.
Sorry, does it mean that message will not block the main window?
Then user instead of closing the message can simply ignore it (e.g. by accidentally clicking oi main window) - which is not a desired behavior.
Do I miss the point?
So we will not block the the main process (good) but it will also not block the main window - providing possibility to ignore the error (not directly bad but questionable) .
There was a problem hiding this comment.
With open, the message should block the interaction with the main window, but not the execution of the code, which is what you do here with the QTimer
There was a problem hiding this comment.
from that page:
Note: Avoid using this function; instead, use open(). Unlike exec(), open() is asynchronous, and does not spin an additional event loop. This prevents a series of dangerous bugs from happening (e.g. deleting the dialog's parent while the dialog is open via exec()). When using open() you can connect to the finished() signal of QDialog to be notified when the dialog is closed.
does it mean that msg object is not deleted after .open()?
If i understood correctly it require Qt::WA_DeleteOnClose.
Otherwise, can it cause a leak?
P.S.
I've tested - it works as you said 👍
There was a problem hiding this comment.
Yes, msg.setAttribute(qt.Qt.WA_DeleteOnClose) is needed.
Adding msg.destroyed.connect(lambda: print("destroyed")) clearly show the difference with and without it.
But wrapper still remain in both cases.
Was not obvious for me.
|
For me it is not clear if this "closing mechanism" is enough, it defiantly will not harm but is it sufficient? |
It should be. |
Sorry i meant about closing |
Those two are not related as far as I can tell. As for the non-blocking message box: this is the first time we introduce this pattern. Probably good to make a helper? def non_blocking_user_warning(...)
msg = qt.QMessageBox(self)
msg.setIcon(qt.QMessageBox.Warning)
msg.setWindowTitle("...")
msg.setText("...")
msg.setInformativeText("...")
msg.setAttribute(qt.Qt.WA_DeleteOnClose)
msg.open() |
| # Without this the file stays "open" in the process | ||
| # and could not be reopened until PyMca restarted. | ||
| try: | ||
| closedSource.close() |
There was a problem hiding this comment.
If self.sourceList is the only object that holds a reference to the h5py.File object then python's garbage collector will close the file at some point after this function (_sourceSelectorSlot) exists.
I don't mind making sure we close the file here in a finally block. Probably better in case there are weird situations (like a logged error callstack that keeps the h5py.File object alive).
| return len(self.getProxyFromIndex(index)) | ||
| except Exception: | ||
| if not self._readErrorReported: | ||
| self._readErrorReported = True |
There was a problem hiding this comment.
FileModel is per source so you will have the error only once per source. A better solution is needed: perhaps refresh at failure is the solution.
If user try to open hdf5 fille during fast scan it crashes.
I could not test it (no simulation of fast scan exist), so please check it carefully...
Error