Ich habe ein problem mit threading.
Code: Alles auswählen
from Tkinter import *
from PIL import Image, ImageTk
import win32com.client
import math
import time
import os
import threading
Document = win32com.client.Dispatch('MaxIm.Document')
FM = win32com.client.Dispatch('FocusMax.FocusControl')
CCDCamera = win32com.client.Dispatch('MaxIm.CCDCamera')
Application = win32com.client.dynamic.Dispatch('MaxIm.Application')
class TestThread (threading.Thread):
def __init__(self):
threading.Thread.__init__(self, name='TestThread')
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]
if added:
name= ' ,'.join (added)
if str(name[-3:])=='fit':
print name
Document.OpenFile('F:/Images/VRT/'+name)
Document.SaveFile('F:/Images/VRT/'+ str(name[0:-4])+'.jpg', 6, 1024,2)
Application.CloseAll()
before = after2
TestThread().start()
Die Error Nachricht sieht so aus:
Exception in thread TestThread:
Traceback (most recent call last):
File "C:\Program Files\Python\lib\threading.py", line 442, in __bootstrap
self.run()
File "G:\Robot teleskop\VRT\soft\GUI.py", line 44, in run
Document.OpenFile("F:/Images/VRT/"+name)
File "C:\Program Files\Python\Lib\site-packages\win32com\client\dynamic.py", line 496, in __getattr__
raise AttributeError, "%s.%s" % (self._username_, attr)
AttributeError: MaxIm.Document.OpenFile
Was ist das fuer ein Error: "raise AttributeError, "%s.%s" % (self._username_, attr)"?
Sonst funktioniert es (Document.Open() und Document.Save()), wenn ich es nicht im Thread starte und wenn "def run (slef)", nicht im code ist, aber dann funktioniert der rest des Programms nicht.
Weiss jehmand wo der Problem liegt? Warum funktioniert es nicht nur, wenn "def run (slef)" im Code ist?
Danke in Vorraus!
Mit freundlichen Gruessen,
Aleksandar
P.S. Habe auch gegooglet. Vielleicht kan euch das helfen:
http://www.gossamer-threads.com/lists/p ... hon/105254
Wenn ja, koennte mir jehmand erklaehren wie man das macht: "Get the module either via cache (ID of the winfay library , Locale, VersionMajor, VersionMinor)", ich bin Anfaenger in Python...