Threading problem

A

Aleksandar Cikota

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
 
F

Faber

Aleksandar said:
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
 
A

Aleksandar Cikota

Thank You, but now it cannot open a file, but it should work...

Here the error message: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 said:
Aleksandar said:
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
 
D

Diez B. Roggisch

Here the error message:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Threating problem 0
Image open problem 2
Async Sleep? 3
Threading problem 2
Threading issue (using alsaaudio) 0
How to use Densenet121 in monai 0
Python battle game help 2
Translater + module + tkinter 1

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,271
Latest member
BuyAtenaLabsCBD

Latest Threads

Top