Watchdog: WinError 58 makes the watchdog to fail the upcoming events

Created on 14 Sep 2015  路  4Comments  路  Source: gorakhargosh/watchdog

Hi all,

When monitoring a folder inside a QNAP, I can get events for newly created files. However, if the new file is a directory, the watchdog crashes with a system error.

I suspect it is because the file is still being copied, but that should not be a reason to crash the listener.

Application is running on Windows 8.1 Pro.
QNAP firmware version: 3.7.2 Build 20120719
Stack Trace:

Exception in thread Thread-3:
Traceback (most recent call last):
  File "C:\Python34\lib\threading.py", line 920, in _bootstrap_inner
    self.run()
  File "C:\Python34\lib\site-packages\watchdog-0.8.3-py3.4.egg\watchdog\observers\api.py", line 146, in run
    self.queue_events(self.timeout)
  File "C:\Python34\lib\site-packages\watchdog-0.8.3-py3.4.egg\watchdog\observers\read_directory_changes.py", line 77, in queue_events
    winapi_events = read_events(self._handle, self.watch.is_recursive)
  File "C:\Python34\lib\site-packages\watchdog-0.8.3-py3.4.egg\watchdog\observers\winapi.py", line 347, in read_events
    buf, nbytes = read_directory_changes(handle, recursive)
  File "C:\Python34\lib\site-packages\watchdog-0.8.3-py3.4.egg\watchdog\observers\winapi.py", line 307, in read_directory_changes
    raise e
  File "C:\Python34\lib\site-packages\watchdog-0.8.3-py3.4.egg\watchdog\observers\winapi.py", line 303, in read_directory_changes
    ctypes.byref(nbytes), None, None)
  File "C:\Python34\lib\site-packages\watchdog-0.8.3-py3.4.egg\watchdog\observers\winapi.py", line 108, in _errcheck_bool
    raise ctypes.WinError()
OSError: [WinError 58] The specified server cannot perform the requested operation.

Most helpful comment

I am also now looking for a solution to delay/retry dirwatcher thread on:
OSError: [WinError 64] The specified network name is no longer available

All 4 comments

Same problem around here, with a WinError 64 and the message : The specified network name is no longer available. This happens when folder is served from a file server that becomes unavailable (SMB share).

How could we catch these kind of error, to retry attaching an observer later ?

I am also now looking for a solution to delay/retry dirwatcher thread on:
OSError: [WinError 64] The specified network name is no longer available

I had the same problem where I was getting the WinError 64 message when monitoring a remote file share. I ended up creating a tiny wrapper around the watchdog.utils.BaseThread class that allows to me catch the error and recover. I then monkeypatch the original BaseThread class with my wrapper before creating an Observer. In my specific case I catch any exceptions that could happen in the run method and add them to a queue to be consumed from in a different thread. It's a hacky solution, but there are not a lot of options without source code changes.

import logging
import threading

import watchdog.utils

logger = logging.getLogger(__name__)


class BaseThreadWrapper(watchdog.utils.BaseThread):
    """
    Wrapper around watchdog BaseThread class.

    """
    queue = None

    def __init__(self):
        super(BaseThreadWrapper, self).__init__()
        self._original_run = self.run
        self.run = self.run_wrapper

    def run_wrapper(self):
        try:
            self._original_run()
        except Exception as e:
            logger.exception('%s thread exited with error',
                             threading.current_thread().name)
            self.queue.put(e)


watchdog.utils.BaseThread = BaseThreadWrapper

What solution (code changes) would you like to see in watchdog?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hgrecco picture hgrecco  路  6Comments

SamSchott picture SamSchott  路  4Comments

gilles380 picture gilles380  路  3Comments

Nikolaissue picture Nikolaissue  路  6Comments

mccarthyryanc picture mccarthyryanc  路  5Comments