From: Ryan W. <big...@gm...> - 2008-03-21 06:18:39
|
Not sure if this is the right list, but I couldn't find one for fuse-python. Anyway, I am having trouble starting a background thread with fuse. The examples I have looked at start the new thread in the __init__ method, but this doesn't seem to be working for me. The thread starts but then quickly ends. Here is the relevant python code I have... class TaskThread(threading.Thread): """Thread that executes a task every N seconds""" def __init__(self): threading.Thread.__init__(self) self._finished = threading.Event() self._interval = 15.0 self.setDaemon(True) def setInterval(self, interval): """Set the number of seconds we sleep between executing our task""" self._interval = interval def shutdown(self): """Stop this thread""" self._finished.set() def run(self): while 1: if self._finished.isSet(): return self.task() # sleep for interval or until shutdown self._finished.wait(self._interval) def task(self): """The task done by this thread - override in subclasses""" pass class GTaskThread(TaskThread): def __init__(self, client): TaskThread.__init__(self) self.client = client def task(self): print 'starting download task' for dir in GDOCS_DIRS: if dir == PHOTOS_DIR: album_feed = self.client.albums_feed() for album in album_feed: photos_feed = self.client.photos_feed(album) for photo in photos_feed: out = None try: album_dir = dir + '/' + album.title.text if not os.path.exists(album_dir): os.mkdir(album_dir) name = album_dir + '/' + photo.title.text out = open(name, 'w') out.write(self.client.get_photo_content(photo)) print 'wrote %s', name finally: if out is not None: out.close() print 'finished download task' class Xmp(Fuse): def __init__(self, user, pw, *args, **kw): Fuse.__init__(self, *args, **kw) self.root = GOOFS_CACHE t = GTaskThread(GClient(user, pw)) t.start() def getattr(self, path): return os.lstat("." + path) def readlink(self, path): return os.readlink("." + path) .... When I run this I see 'starting download task' and then that's it. If I run without integrating with fuse the Task runs as expected. Any help would be greatly appreciated. Thanks, Ryan |