<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Threading for observering file content in Revit API Forum</title>
    <link>https://forums.autodesk.com/t5/revit-api-forum/threading-for-observering-file-content/m-p/7443578#M55613</link>
    <description>&lt;P&gt;i want to implement a file observing with RevitPythonShell. i got 2 solutions which run perfectly with IronPython but get stacked (Revit closed without any error show up ) when use with PythonRevitShell. Please someone help me to decrypt this fault?&lt;/P&gt;&lt;P&gt;1. Use System IO&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;from System.IO import FileSystemWatcher
from System.Threading import Thread
def onChanged(source, event):
    print 'Changed:', event.ChangeType, event.FullPath
def onRenamed(source, event):
    print 'Renamed:', event.OldFullPath, event.FullPath
watcher = FileSystemWatcher()
watcher.Path = 'D:\\temp'
watcher.Filter = 'test.log'

watcher.Changed += onChanged
watcher.Created += onChanged
watcher.Deleted += onChanged
watcher.Renamed += onRenamed

watcher.EnableRaisingEvents = True 

Thread.Sleep(60 * 1000 * 60) # Revit closed when i add this line&lt;/PRE&gt;&lt;P&gt;2. Use watchdog python&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;class MyEventHandler(PatternMatchingEventHandler):
    def on_moved(self, event):
        super(MyEventHandler, self).on_moved(event)
        logging.info("File %s was just moved" % event.src_path)

    def on_created(self, event):
        super(MyEventHandler, self).on_created(event)
        logging.info("File %s was just created" % event.src_path)

    def on_deleted(self, event):
        super(MyEventHandler, self).on_deleted(event)
        logging.info("File %s was just deleted" % event.src_path)

    def on_modified(self, event):
        super(MyEventHandler, self).on_modified(event)
        logging.info("File %s was just modified" % event.src_path)

def main(file_path=None):
    logging.basicConfig(level=logging.INFO,
        format='%(asctime)s - %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S')
    watched_dir = os.path.split(file_path)[0]
    print 'watched_dir = {watched_dir}'.format(watched_dir=watched_dir)
    patterns = [file_path]
    print 'patterns = {patterns}'.format(patterns=', '.join(patterns))
    event_handler = MyEventHandler(patterns=patterns)
    observer = Observer()
    observer.schedule(event_handler, watched_dir, recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()

if __name__ == "__main__":
    main(log_path)              &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 09 Oct 2017 01:51:16 GMT</pubDate>
    <dc:creator>Anonymous</dc:creator>
    <dc:date>2017-10-09T01:51:16Z</dc:date>
    <item>
      <title>Threading for observering file content</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/threading-for-observering-file-content/m-p/7443578#M55613</link>
      <description>&lt;P&gt;i want to implement a file observing with RevitPythonShell. i got 2 solutions which run perfectly with IronPython but get stacked (Revit closed without any error show up ) when use with PythonRevitShell. Please someone help me to decrypt this fault?&lt;/P&gt;&lt;P&gt;1. Use System IO&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;from System.IO import FileSystemWatcher
from System.Threading import Thread
def onChanged(source, event):
    print 'Changed:', event.ChangeType, event.FullPath
def onRenamed(source, event):
    print 'Renamed:', event.OldFullPath, event.FullPath
watcher = FileSystemWatcher()
watcher.Path = 'D:\\temp'
watcher.Filter = 'test.log'

watcher.Changed += onChanged
watcher.Created += onChanged
watcher.Deleted += onChanged
watcher.Renamed += onRenamed

watcher.EnableRaisingEvents = True 

Thread.Sleep(60 * 1000 * 60) # Revit closed when i add this line&lt;/PRE&gt;&lt;P&gt;2. Use watchdog python&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;class MyEventHandler(PatternMatchingEventHandler):
    def on_moved(self, event):
        super(MyEventHandler, self).on_moved(event)
        logging.info("File %s was just moved" % event.src_path)

    def on_created(self, event):
        super(MyEventHandler, self).on_created(event)
        logging.info("File %s was just created" % event.src_path)

    def on_deleted(self, event):
        super(MyEventHandler, self).on_deleted(event)
        logging.info("File %s was just deleted" % event.src_path)

    def on_modified(self, event):
        super(MyEventHandler, self).on_modified(event)
        logging.info("File %s was just modified" % event.src_path)

def main(file_path=None):
    logging.basicConfig(level=logging.INFO,
        format='%(asctime)s - %(message)s',
        datefmt='%Y-%m-%d %H:%M:%S')
    watched_dir = os.path.split(file_path)[0]
    print 'watched_dir = {watched_dir}'.format(watched_dir=watched_dir)
    patterns = [file_path]
    print 'patterns = {patterns}'.format(patterns=', '.join(patterns))
    event_handler = MyEventHandler(patterns=patterns)
    observer = Observer()
    observer.schedule(event_handler, watched_dir, recursive=True)
    observer.start()
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()

if __name__ == "__main__":
    main(log_path)              &lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 09 Oct 2017 01:51:16 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/threading-for-observering-file-content/m-p/7443578#M55613</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2017-10-09T01:51:16Z</dc:date>
    </item>
    <item>
      <title>Re: Threading for observering file content</title>
      <link>https://forums.autodesk.com/t5/revit-api-forum/threading-for-observering-file-content/m-p/7456355#M55614</link>
      <description>&lt;P&gt;The Revit API does not&amp;nbsp;support multi-threading:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;A href="http://thebuildingcoder.typepad.com/blog/2014/11/the-revit-api-is-never-ever-thread-safe.html" target="_blank"&gt;http://thebuildingcoder.typepad.com/blog/2014/11/the-revit-api-is-never-ever-thread-safe.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 12 Oct 2017 21:17:07 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/revit-api-forum/threading-for-observering-file-content/m-p/7456355#M55614</guid>
      <dc:creator>jeremytammik</dc:creator>
      <dc:date>2017-10-12T21:17:07Z</dc:date>
    </item>
  </channel>
</rss>

