473,573 Members | 3,023 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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('MaxI m.Document')
Application = win32com.client .Dispatch('MaxI m.Application')
p = win32com.client .dynamic.Dispat ch('PinPoint.Pl ate')


class TestThread ( threading.Threa d ):
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.OpenFi le('F:/Images/VRT/'+name)
Document.SaveFi le('F:/Images/VRT/'+
str(name[0:-4])+'.jpg', 6, 1024,2)
Application.Clo seAll()

try:
p.AttachFITS('F :/Images/VRT/'+name)
p.ArcsecPerPixe lHoriz = -1.7
p.ArcsecPerPixe lVert = -1.7
p.MaxMatchResid ual = 1.0
p.FitOrder = 3
p.CentroidAlgor ithm = 0
p.RightAscensio n = p.TargetRightAs cension
p.Declination = p.TargetDeclina tion
p.Catalog = 0 # GSC
p.CatalogPath = 'F:/'
p.ProjectionTyp e = 1 #
p.Solve()
p.DetachFITS()

pRA = p.RightAscensio n
pDec = p.Declination
print pRA
print pDec

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


TestThread().st art()




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

Best regards,
Aleksandar




Apr 17 '06 #1
3 2167
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('MaxI m.Document')
Application = win32com.client .Dispatch('MaxI m.Application')
p = win32com.client .dynamic.Dispat ch('PinPoint.Pl ate')

class TestThread ( threading.Threa d ):
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().st art()


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\li b\threading.py" , line 442, in __bootstrap
self.run()
File "G:\Robot teleskop\VRT\te st\test2.py", line 25, in run
Document.OpenFi le('F:/Images/VRT/'+name)
File "C:\Program
Files\Python\Li b\site-packages\win32c om\client\dynam ic.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('MaxI m.Document')
Application = win32com.client .Dispatch('MaxI m.Application')
p = win32com.client .dynamic.Dispat ch('PinPoint.Pl ate')

class TestThread (threading.Thre ad):
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.OpenFi le('F:/Images/VRT/'+name)
Document.SaveFi le('F:/Images/VRT/'+
str(name[0:-4])+'.jpg', 6, 1024,2)
Application.Clo seAll()
try:
p.AttachFITS('F :/Images/VRT/'+name)
p.ArcsecPerPixe lHoriz = -1.7
p.ArcsecPerPixe lVert = -1.7
p.MaxMatchResid ual = 1.0
p.FitOrder = 3
p.CentroidAlgor ithm = 0
p.RightAscensio n = p.TargetRightAs cension
p.Declination = p.TargetDeclina tion
p.Catalog = 0 # GSC
p.CatalogPath = 'F:/'
p.ProjectionTyp e = 1 #
p.Solve()
p.DetachFITS()
pRA = p.RightAscensio n
pDec = p.Declination
print pRA
print pDec
except:
p.DetachFITS()
print 'Error'
before = after2
TestThread().st art()


"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******@liber o.it> wrote in message
news:OQ******** *************@t wister1.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('MaxI m.Document')
Application = win32com.client .Dispatch('MaxI m.Application')
p = win32com.client .dynamic.Dispat ch('PinPoint.Pl ate')

class TestThread ( threading.Threa d ):
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().st art()


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\li b\threading.py" , line 442, in
__bootstrap
self.run()
File "G:\Robot teleskop\VRT\te st\test2.py", line 25, in run
Document.OpenFi le('F:/Images/VRT/'+name)
File "C:\Program
Files\Python\Li b\site-packages\win32c om\client\dynam ic.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

65
6693
by: Anthony_Barker | last post by:
I have been reading a book about the evolution of the Basic programming language. The author states that Basic - particularly Microsoft's version is full of compromises which crept in along the language's 30+ year evolution. What to you think python largest compromises are? The three that come to my mind are significant whitespace,...
19
6450
by: Jane Austine | last post by:
As far as I know python's threading module models after Java's. However, I can't find something equivalent to Java's interrupt and isInterrupted methods, along with InterruptedException. "somethread.interrupt()" will wake somethread up when it's in sleeping/waiting state. Is there any way of doing this with python's thread? I suppose thread...
17
2417
by: Andrae Muys | last post by:
Found myself needing serialised access to a shared generator from multiple threads. Came up with the following def serialise(gen): lock = threading.Lock() while 1: lock.acquire() try: next = gen.next() finally:
2
2960
by: Egor Bolonev | last post by:
hi all my program terminates with error i dont know why it tells 'TypeError: run() takes exactly 1 argument (10 given)' =program==================== import os, os.path, threading, sys def get_all_files(path): """return all files of folder path, scan with subfolders
77
5232
by: Jon Skeet [C# MVP] | last post by:
Please excuse the cross-post - I'm pretty sure I've had interest in the article on all the groups this is posted to. I've finally managed to finish my article on multi-threading - at least for the moment. I'd be *very* grateful if people with any interest in multi-threading would read it (even just bits of it - it's somewhat long to go...
11
5004
by: Paul Sijben | last post by:
I am stumped by the following problem. I have a large multi-threaded server accepting communications on one UDP port (chosen for its supposed speed). I have been profiling the code and found that the UDP communication is my biggest drain on performance! Communication where the client and the server are on the same machine still takes 300ms...
17
6398
by: OlafMeding | last post by:
Below are 2 files that isolate the problem. Note, both programs hang (stop responding) with hyper-threading turned on (a BIOS setting), but work as expected with hyper-threading turned off. Note, the Windows task manager shows 2 CPUs on the Performance tab with hyper-threading is turned on. Both Python 2.3.5 and 2.4.3 (downloaded from...
9
1845
by: cgwalters | last post by:
Hi, I've recently been working on an application which does quite a bit of searching through large data structures and string matching, and I was thinking that it would help to put some of this CPU-intensive work in another thread, but of course this won't work because of Python's GIL. There's a lot of past discussion on this, and I want...
5
6923
by: CCLeasing | last post by:
For an application I'm creating I want to create a 'fake' progress bar. By fake I mean a progress bar that looks like it's doing something but actually isn't. I know philosophically this isn't sound. But my little app is a 'fake' app and is designed to look like another - hence this seeming crazy situation of needing to fake a progess bar....
126
6654
by: Dann Corbit | last post by:
Rather than create a new way of doing things: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2497.html why not just pick up ACE into the existing standard: http://www.cse.wustl.edu/~schmidt/ACE.html the same way that the STL (and subsequently BOOST) have been subsumed? Since it already runs on zillions of platforms, they have...
0
7783
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7701
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8029
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8204
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
6424
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5600
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3734
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3735
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2222
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.