469,923 Members | 1,777 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,923 developers. It's quick & easy.

Threading problem

Hi all,

I have a problem with threading. The following part should be running in a
main programm all the time, but so that the main programm also works (like 2
seperate programms, but in one)
How to integrate the Code-part in the main programm, so that the
mainprogramm works?

Code:

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 ):
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':
Document.OpenFile('F:/Images/VRT/'+name)
Document.SaveFile('F:/Images/VRT/'+
str(name[0:-4])+'.jpg', 6, 1024,2)
Application.CloseAll()

try:
p.AttachFITS('F:/Images/VRT/'+name)
p.ArcsecPerPixelHoriz = -1.7
p.ArcsecPerPixelVert = -1.7
p.MaxMatchResidual = 1.0
p.FitOrder = 3
p.CentroidAlgorithm = 0
p.RightAscension = p.TargetRightAscension
p.Declination = p.TargetDeclination
p.Catalog = 0 # GSC
p.CatalogPath = 'F:/'
p.ProjectionType = 1 #
p.Solve()
p.DetachFITS()

pRA = p.RightAscension
pDec = p.Declination
print pRA
print pDec

except:
p.DetachFITS()
print 'Error'
before = after2


TestThread().start()




For your prompt reply, I say thank you in advance.

Best regards,
Aleksandar




Apr 17 '06 #1
3 2003
Aleksandar Cikota wrote:
How to integrate the Code-part in the main programm, so that the
mainprogramm works?

Code:

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 ):
path_to_watch = "F:/Images/VRT/"
def run(self):
# Put the following code in the run method
before = dict ([(f, None) for f in os.listdir (path_to_watch)])
while 1:
[cut]
TestThread().start()


This should work

--
Faber
http://faberbox.com/
http://smarking.com/

The man who trades freedom for security does not deserve nor will he ever
receive either. -- Benjamin Franklin
Apr 17 '06 #2
Thank You, but now it cannot open a file, but it should work...

Here the error message:
Exception in thread Thread-1:
Traceback (most recent call last):
File "C:\Program Files\Python\lib\threading.py", line 442, in __bootstrap
self.run()
File "G:\Robot teleskop\VRT\test\test2.py", line 25, 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

And here the Code:

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]
if added:
name= ' ,'.join (added)
if str(name[-3:])=='fit':
Document.OpenFile('F:/Images/VRT/'+name)
Document.SaveFile('F:/Images/VRT/'+
str(name[0:-4])+'.jpg', 6, 1024,2)
Application.CloseAll()
try:
p.AttachFITS('F:/Images/VRT/'+name)
p.ArcsecPerPixelHoriz = -1.7
p.ArcsecPerPixelVert = -1.7
p.MaxMatchResidual = 1.0
p.FitOrder = 3
p.CentroidAlgorithm = 0
p.RightAscension = p.TargetRightAscension
p.Declination = p.TargetDeclination
p.Catalog = 0 # GSC
p.CatalogPath = 'F:/'
p.ProjectionType = 1 #
p.Solve()
p.DetachFITS()
pRA = p.RightAscension
pDec = p.Declination
print pRA
print pDec
except:
p.DetachFITS()
print 'Error'
before = after2
TestThread().start()


"raise AttributeError, "%s.%s" % (self._username_, attr)", what does it
mean?
For your prompt reply, I say thank you in advance.

Best regards,
Aleksandar


"Faber" <za******@libero.it> wrote in message
news:OQ*********************@twister1.libero.it... Aleksandar Cikota wrote:
How to integrate the Code-part in the main programm, so that the
mainprogramm works?

Code:

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 ):
path_to_watch = "F:/Images/VRT/"


def run(self):
# Put the following code in the run method
before = dict ([(f, None) for f in os.listdir (path_to_watch)])
while 1:


[cut]
TestThread().start()


This should work

--
Faber
http://faberbox.com/
http://smarking.com/

The man who trades freedom for security does not deserve nor will he ever
receive either. -- Benjamin Franklin

Apr 17 '06 #3
> Here the error message:
Exception in thread Thread-1:

Traceback (most recent call last):
File "C:\Program Files\Python\lib\threading.py", line 442, in
__bootstrap
self.run()
File "G:\Robot teleskop\VRT\test\test2.py", line 25, 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


Seems that you think it should doesn't impress the COM-object of type
MaxIm.Document very much. Play around with that w/o threads if it works.

Diez
Apr 18 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

65 posts views Thread by Anthony_Barker | last post: by
19 posts views Thread by Jane Austine | last post: by
17 posts views Thread by Andrae Muys | last post: by
2 posts views Thread by Egor Bolonev | last post: by
11 posts views Thread by Paul Sijben | last post: by
9 posts views Thread by cgwalters | last post: by
126 posts views Thread by Dann Corbit | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.