[python-users] Hilfe bei Debugging eines Moduls gesucht (auch kommerziell)

André Aulich info at andre-aulich.de
Di Feb 21 00:07:38 CET 2012


Guten Abend, die Herren,

ich beschäftige mich seit kurzem mit Python und bastele gerade
ein Tool, das das Modul MacFSEvents verwendet:

https://github.com/malthe/macfsevents

Ich habe in dem Modul einen Fehler gefunden, der im Python-Teil
der Implementierung zu stecken scheint, und wäre dankbar, wenn
mich jemand bei der Fehlerbehebung unterstützen könnte.

Gerne würde ich auch einen Dienstleister dafür buchen, wenn
sich also jemand von Euch dazu berufen fühlt, wäre das klasse.

Das Problem gestaltet sich wie folgt:

> When I watch a folder with subdirectories inside it and then
> create a new subdirectory or file inside the watched folder,
> all the other, already existing but still unchanged subdirectories
> get the fsevent mask 256, which means created.
> 
> E.g. if this is the folder I watch, incl. subdirs:
> 
> 
> 
> 
> Then I copy the file 1.png into the test folder:
> 
> 
> 
> The events I receive, now, are:
> ---------------
> file name: /test/1.png
> Mask: 256, Cookie: None
> ---------------
> file name: test/subdir2
> Mask: 256, Cookie: None
> ---------------
> file name: /test/subdir3
> Mask: 256, Cookie: None
> ---------------
> file name: /est/subdir1
> Mask: 256, Cookie: None
> 
> This happens only the first time I copy something into a folder
> after I start your module.
> 
> To me it looks as if your tool does the following:
> 
> The first time I copy something into a folder, your tool lists its
> contents and keeps a reflection of that in memory.
> As macfsevents doesn't know what the directory listing looked
> like before the initial event, it marks all contained folders as
> created (256). If there are files inside a folder, they only receive
> an event if they are really changed.

Es sieht so aus, als wenn in diesem Code:

https://github.com/malthe/macfsevents/blob/master/fsevents.py

irgendwo ein Problem steckt, das zu dem oben beschriebenen
Verhalten führt.

Ein paar Vermutungen meinerseits habe ich dem Entwickler
geschickt:

> it's a bit hard for me to understand how your code works (I am fairly new
> to Python), but at least I got a rough idea, now.
> 
> As far as I can see, the c file _fsevents.c seems to be okay
> (https://github.com/malthe/macfsevents/blob/master/_fsevents.c).
> 
> The issue seems to be in fsevents.py
> (https://github.com/malthe/macfsevents/blob/master/fsevents.py),
> where you snapshot the filesystem to compare fsevents to changes
> in the filesystem.
> 
> This seems to happen in the class
> 
> FileEventCallback
> 
> I am not exactly sure which part of the class really causes the issue,
> but here are some ideas:
> 
> In line 165 and 166 it says:
> 
>                else:
>                    event = FileEvent(IN_CREATE, None, filename)
> 
> As far as I can see, this would trigger a "created" event for all
> folders in the current directory, and snapshoting the directories
> right after doesn't delete the event.
> Can this cause the issue?
> 
> In lines 168 and 169 it says:
> 
> if os.path.isdir(filename):
>                    self.snapshot(filename)
> 
> If this triggers the creation of the "created" event, could it be an
> issue, that this happens much later than the snapshot of the
> normal files?
> 
> From line 179 on you define the function snapshot:
> 
>    def snapshot(self, path):
>        path = os.path.realpath(path)
>        refs = self.snapshots
>        refs[path] = {}
> 
>        for root, dirs, files in os.walk(path):
>            entry = refs[root]
>            for filename in files:
>                try:
>                    entry[filename] = os.stat(os.path.join(root, filename))
>                except OSError:
>                    continue
>            for directory in dirs:
>                refs[os.path.join(root, directory)] = {}
> 
>        if os.path.isdir(path):
>            refs[os.path.join(root, path)] = {}
>            for name in os.listdir(os.path.join(root, path)):
>                try:
>                    refs[path][name] = os.stat(os.path.join(path, name))
>                except OSError:
>                    pass
> 
> There are a couple of things which are not obvious to me inside
> this function, but as I said, I am fairly new to Python.
> 
> Why is there a for loop for root, dirs and files, but instead of
> dealing with dirs inside this loop, you just create an empty
> dictionary for refs and start an if block on the same level
> right after?
> 
> If you could have a look at these things, that would be great!
> 
> As this is your code, it might be faster for you to fix it than
> for me. Especially if we consider the level of expertise :-)

Auch wenn sich der Entwickler noch einmal bei mir melden sollte,
so scheint er aktuell keine Zeit zu haben, sich mit der Materie
zu beschäftigen, und ich wäre recht dankbar, wenn mir jemand
mindestens bei diesem Teil, evtl. auch an anderen Stellen in
meinem aktuellen Projekt Hilfe leisten könnte.

Wenn also jemand Zeit für ein kleines Projekt hat, würde ich
mich sehr über eine Rückmeldung freuen.

Schöne Grüße und noch ein paar schöne Karnevalstage,

André Aulich

--
André Aulich
Digital Asset Management & Workflow Automation

phone:	+49 (0)221 - 99 81 545
mobile:	+49 (0)173 - 25 17 719

mail:	info at andre-aulich.de
web:	www.andre-aulich.de

Hatzfeldstr. 6
51069 Köln
Germany

-------------- nächster Teil --------------
Ein Dateianhang mit HTML-Daten wurde abgetrennt...
URL: <http://lists.uni-koeln.de/pipermail/python-users/attachments/20120221/f2cd893d/attachment.html>
-------------- nächster Teil --------------
Ein Dateianhang mit Binärdaten wurde abgetrennt...
Dateiname   : 1.png
Dateityp    : image/png
Dateigröße  : 7075 bytes
Beschreibung: nicht verfügbar
URL         : <http://lists.uni-koeln.de/pipermail/python-users/attachments/20120221/f2cd893d/attachment.png>
-------------- nächster Teil --------------
Ein Dateianhang mit Binärdaten wurde abgetrennt...
Dateiname   : 2.png
Dateityp    : image/png
Dateigröße  : 7341 bytes
Beschreibung: nicht verfügbar
URL         : <http://lists.uni-koeln.de/pipermail/python-users/attachments/20120221/f2cd893d/attachment-0001.png>


Mehr Informationen über die Mailingliste python-users