Python Threading with win32ui DDE module
Running Python2.7 32 bit Windows. It would appear that the dde module (or
the way I am using it?) does not play nicely with threads.
Here's stripped down code to demonstrate:
This Works:
(I.E. Doesn't fail epically.)
import win32ui
import dde
import threading
class Conversation(threading.Thread):
def __init__(self, server, first, second, tag)
self.tag = tag #string
self.first = first #string
self.second = second #string
self.server = server #dde server object
self.conversation = dde.CreateConversation(server)
#The focus of the problem. Here it works.
self.conversation.ConnectTo(self.first, self.second)
def run(self):
print ""
def main():
machine = "Irrelevant_MachineName"
tag = "Irrelevant_Tagname"
server = dde.CreateServer()
server.Create("Irrelevant_ServerName")
t = Conversation(server, "Irrelevant_Name", machine, tag)
t.start()
main()
This doesn't:
class Conversation(threading.Thread):
def __init__(self, server, first, second, tag):
self.tag = tag #string
self.first = first #string
self.second = second #string
self.server = server #dde server object
def run(self):
self.conversation = dde.CreateConversation(server)
#Focus of problem.
#Inside here it does not work.
self.conversation.ConnectTo(self.name1, self.name2)
def main():
machine = "Irrelevant_MachineName"
tag = "Irrelevant_Tagname"
server = dde.CreateServer()
server.Create("Irrelevant_ServerName")
t = Conversation(server, "Irrelevant_Name", machine, tag)
t.start()
main()
When it fails, I get this error:
Exception in thread Thread-1:
Traceback (most recent call last):
File "c:\Python27\lib\threading.py", line 808, in __bootstrap_inner
self.run()
File "DDE.py", line 28 in run
self.conversation.ConnectTo(self.first, self.second)
error: ConnectTo failed
Which corresponds, as one might expect, to Why would this be? This is
going to be my first multithreaded program, so I'm not sure if I'm doing
something stupid here.
But to me it seems perfectly reasonable that I should be able to call the
dde.server.conversation object's ConnectTo method from within the
threading module's "run()" method.
I'd looked into multiprocessing, but I don't think that's as applicable to
my situation.
So, any ideas? I would greatly appreciate the help!!!
No comments:
Post a Comment