Watchdog: Python 2.7 and windows 7

Created on 5 Dec 2011  路  3Comments  路  Source: gorakhargosh/watchdog

Since I had some problems with python2.5, I tried also python 2.7 and now I get a different error:
(I guess something wrong with ctypes and the windows dlls, but I can't tell much more than that...)

C-c C-cException in thread Thread-2:
Traceback (most recent call last):
File "c:Python27libthreading.py", line 552, in __bootstrap_inner
self.run()
File "c:Python27libsite-packageswatchdog-0.5.4-py2.7.eggwatchdogobserversapi.py", line 192, in run
self.queue_events(self.timeout)
File "c:Python27libsite-packageswatchdog-0.5.4-py2.7.eggwatchdogobserversread_directory_changes.py", line 80, in queue_events
self.watch.is_recursive)
File "c:Python27libsite-packageswatchdog-0.5.4-py2.7.eggwatchdogobserverswinapi_common.py", line 130, in read_directory_changes
None)
File "c:Python27libsite-packageswatchdog-0.5.4-py2.7.eggwatchdogobserverswinapi.py", line 103, in _errcheck_bool
raise ctypes.WinError()
WindowsError: [Error 1] Incorrect function.

Incomplete (need more info) windows

Most helpful comment

Did some digging into the windows api on my own and sure enough I was able to identify the problem.

Looking up the return values of ReadDirectoryChangesW I found the following:

If the network redirector or the target file system does not support this operation, the function fails with ERROR_INVALID_FUNCTION.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365465(v=vs.85).aspx

I've been working on a network share.
Copying the files I need to watch to a local filesystem fixed it for me.

I'll leave this here in case anyone else finds this issue while googling the error message.

All 3 comments

Hi,
I'm sorry for bumping this two year old issue, but just ran into the exact same problem with Windows 10, python2.7 and watchdog 0.8.3

It can be reproduced by the following piece of code:

import time

from watchdog.observers import Observer
from watchdog.events import FileSystemEventHandler

class Handler(FileSystemEventHandler):
    def on_any_event(self, event):
        print "File changed: %s" % event.src_path

if __name__ == '__main__':
    event_handler = Handler()
    observer = Observer()
    observer.schedule(event_handler, '.', recursive=True)
    observer.start()

    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()

The resulting exception looks like this:

Exception in thread Thread-2:
Traceback (most recent call last):
  File "c:\python27\Lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Users\IEUser\Envs\xtrude\lib\site-packages\watchdog\observers\api.py", line 146, in run
    self.queue_events(self.timeout)
  File "C:\Users\IEUser\Envs\xtrude\lib\site-packages\watchdog\observers\read_directory_changes.py", line 77, in queue_events
    winapi_events = read_events(self._handle, self.watch.is_recursive)
  File "C:\Users\IEUser\Envs\xtrude\lib\site-packages\watchdog\observers\winapi.py", line 347, in read_events
    buf, nbytes = read_directory_changes(handle, recursive)
  File "C:\Users\IEUser\Envs\xtrude\lib\site-packages\watchdog\observers\winapi.py", line 307, in read_directory_changes
    raise e
WindowsError: [Error 1] Incorrect function.

Please tell me if you need any further information.

Did some digging into the windows api on my own and sure enough I was able to identify the problem.

Looking up the return values of ReadDirectoryChangesW I found the following:

If the network redirector or the target file system does not support this operation, the function fails with ERROR_INVALID_FUNCTION.
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365465(v=vs.85).aspx

I've been working on a network share.
Copying the files I need to watch to a local filesystem fixed it for me.

I'll leave this here in case anyone else finds this issue while googling the error message.

This helped me just today. Maybe we should raise a custom error with a little bit more detailed message of why this happened (Or maybe just a link to this issue)

Was this page helpful?
0 / 5 - 0 ratings