Opened 11 years ago

Closed 11 years ago

#4399 defect closed fixed (fixed)

inotify example code doesn't actually work

Reported by: Benjamin Peterson Owned by:
Priority: high Milestone: Twisted-10.1
Component: core Keywords: documentation, easy
Cc: Branch:
Author:

Description (last modified by Jean-Paul Calderone)

Running the code in the inotify.py docstring gives

Traceback (most recent call last):
  File "x.py", line 10, in <module>
    notifier.watch("twisted", callbacks=[notify], recursive=True)
  File "/home/benjamin/dev/repos/twisted/twisted/internet/inotify.py", line 346, in watch
    for child in path.walk():
AttributeError: 'str' object has no attribute 'walk'

Looking past this issue, it seems the callback accepts too many args.

Attachments (1)

inotify.py-4399.patch (911 bytes) - added by Adrian Overbury 11 years ago.
Patch to correct the example code in inotify.py so that it actually runs

Download all attachments as: .zip

Change History (6)

comment:1 Changed 11 years ago by Jean-Paul Calderone

Description: modified (diff)
Keywords: documentation easy added
Milestone: Twisted-10.1
Priority: normalhigh

fixing description markup

Changed 11 years ago by Adrian Overbury

Attachment: inotify.py-4399.patch added

Patch to correct the example code in inotify.py so that it actually runs

comment:2 Changed 11 years ago by Adrian Overbury

Keywords: review added
Owner: Glyph deleted

The problem with the example code is that it was passing in the path to be watched as a string, when the code was expecting a FilePath object from twisted.python.filepath. It should also probably be noted in the example code that this just sets a watch on the path -- you need to run notifier.doRead() in a loop in order to actually get any notification events out of it.

comment:3 Changed 11 years ago by Jean-Paul Calderone

Keywords: review removed
Owner: set to Jean-Paul Calderone
Status: newassigned

Thanks. This looks good, and your point about needing a reactor to be running is a good one. I'm going to add a note about that and then apply this.

comment:4 Changed 11 years ago by Jean-Paul Calderone

Resolution: fixed
Status: assignedclosed

(In [28866]) Apply inotify module docstring example fix patch

Author: aoverbury Reviewer: exarkun Fixes: #4399

Fix the inotify example in the twisted.internet.inotify module docstring to use the watch and callback APIs properly (they accept FilePath instances, not str instances). Also drop the unused extraArg parameter.

comment:5 Changed 11 years ago by <automation>

Owner: Jean-Paul Calderone deleted
Note: See TracTickets for help on using tickets.