Friday 15 March 2013

python pyinotify doesn't work with os.listdir() or glob.glob() -



python pyinotify doesn't work with os.listdir() or glob.glob() -

i trying create simple piece of software automatically makes list based on file contents of newly inserted usb memory stick.

using ubuntu 14.04.

now using os.listdir() , glob.glob() work fine on own...

however when using pyinotify, , getting input_dir os.listdir() or glob.glob() event.pathname ... blank list every time...

tried concatenating strings add together single quotes, double quotes etc... no avail.

here's snippet of code

#!/usr/bin/python #notifier setup import pyinotify, os, glob wm=pyinotify.watchmanager() class eventhandler(pyinotify.processevent): def process_in_create(self,event): global path path = event.pathname usb_insertion() def usb_insertion(): print glob.glob(path+"/*") print "listdir", os.listdir(path) handler=eventhandler() notifier=pyinotify.notifier(wm, handler) wdd=wm.add_watch('/media', pyinotify.in_create, rec=true) notifier.loop()

i have solved in case interested.

adding time.sleep(2) before doing glob or os.listdir() seems have done it.

python python-2.7 ubuntu-14.04 pyinotify

No comments:

Post a Comment