On Tue, 18 Apr 2006 15:01:10 +0200 (Central European Daylight Time), "Aleksandar Cikota" <[EMAIL PROTECTED]> wrote:
>I have a problem with threading. > > Why do you think it is a threading problem? Does this exact program work if you replace TestThread().start() with TestThread().run()? Do you know for certain that the MaxIm objects are thread safe? You're creating the documents in one thread and using them in another. >import win32com.client >import time >import os >import threading >Document = win32com.client.Dispatch('MaxIm.Document') >Application = win32com.client.Dispatch('MaxIm.Application') >p = win32com.client.dynamic.Dispatch('PinPoint.Plate') >class TestThread (threading.Thread): > def run (self): > path_to_watch = "F:/Images/VRT/" > before = dict ([(f, None) for f in os.listdir (path_to_watch)]) > while 1: > time.sleep(2) > after2 = dict ([(f, None) for f in os.listdir (path_to_watch)]) > added = [f for f in after2 if not f in before] > > As a side note, why do you turn these into dicts instead of just leaving them as lists? Given your usage, this seems like unnecessary extra overhead. And this code can't be right. If there are multiple new files in the directory, your "name" string will contain ALL of them, and it's virtually certain that OpenFile won't know how to handle that. > if added: > name= ' ,'.join (added) > if str(name[-3:])=='fit': > > The "str" is unnecessary here. "name" is already a string. > print name > Document.OpenFile('F:/Images/VRT/'+name) > Document.SaveFile('F:/Images/VRT/'+ >str(name[0:-4])+'.jpg', 6, 1024,2) > Application.CloseAll() > > Does CloseAll close the application? If so, doesn't that make the Document objects evaporate? Why don't you create the Document and Application objects in your inner loop? There's no sense in forcing an instance of the application to stick around all the time when it's only going to be asked to operate occasionally. > before = after2 >TestThread().start() > -- Tim Roberts, [EMAIL PROTECTED] Providenza & Boekelheide, Inc. _______________________________________________ Python-win32 mailing list Python-win32@python.org http://mail.python.org/mailman/listinfo/python-win32