My program utilises Qt's QFileSystemWatcher
function to monitor a network directory (not on the local machine itself) for changes, and then run a script when a change is found. This function performs as required for the most part. The program is designed to run 24/7, which has raised some issues using this particular function.
The error which is causing issues is as follows:
QFileSystemWatcher: FindNextChangeNotification failed!! (The specified network name is no longer available.)
The functionality I'd like to implement is as follows:
- Build in error handling surrounding network availability for
QFileSystemWatcher
- If the network becomes unavailable and the error is raised, go to
Script()
- Run
Script()
for handling the unavailable network
Given that the QFileSystemWatcher
function is established in the initialisation of the program, I'm not sure how to go about error handling. Here's the basic outline of my current code:
class Main(QMain, Ui_Main):
def __init__(self, parent=None):
super(Main, self).__init__(parent)
self.setupUi(self)
self.DirectoryWatcher = QtCore.QFileSystemWatcher([r'U:\NetworkAddress\Directory'])
self.DirectoryWatcher.directoryChanged.connect(self.GoToThisDirectory)
def GoToThisDirectory(self):
print("foo")
Is there a way to explicitly establish error handling for the 'FindNextChangeNotification'
error? Any input would be greatly appreciated!