<p>Hi,</p>
<p>I need to connect to a PerspectiveBroker from a VB application. <br>I did it with a com server in python, which works fine when the com client is also python code.<br>All the calls must be synchronous to the com server.
<br>When Calling from VB it works fine every time if the function used from the com server don't use the reactor.</p>
<p>The problem is that when I call (from the VB com client) the functions that uses the twisted reactor it performs well the first time but for the the second time it's called, it stalls. I have to kill the vb executable.
<br>The function from the test code is: testBroker()</p>
<div>Please can you help me to sheed some light on this? Should I do it another way? Bellow is the code that I am using.</div>
<div><br>Many thanks</div>
<p>Miguel</p>
<p>----------------------------------------------------<br>The code for the python com client :</p>
<p>import win32com.client<br>object = win32com.client.Dispatch("Python.TestServer")<br>print object.Hello("test")<br>print object.Hello2("test")<br>print object.testBroker()<br>print object.gettestresult
()</p>
<p>----------------------------------------------------<br>The code for the VB com client:</p>
<div>Private Sub TestComServer()<br> Dim y As Object<br> Set y = CreateObject("Python.TestServer") <br> MsgBox y.gettestresult<br> MsgBox y.testBroker()<br> MsgBox y.gettestresult()<br> Set y = Nothing</div>
<div>End Sub</div>
<p>----------------------------------------------------<br>the code for the python comserver:</p>
<p>#testcom.py<br>from twisted.spread import pb<br>from twisted.internet import reactor, defer<br>from twisted.python import util<br>import sys<br>import time<br>import socket </p>
<p>class HelloWorld:<br> _reg_clsid_ = "{7CC9F362-486D-11D1-BB48-0000E838A65F}"<br> _reg_desc_ = "Python Test COM Server"<br> _reg_progid_ = "Python.TestServer"<br> _public_methods_ = ['testBroker','gettestresult']
<br> def __init__(self):<br> self.sText='sText10'<br> self.reactorFinished=False <br> def get_ip(self):<br> addrs = socket.getaddrinfo(socket.gethostname(), None)<br> addr = addrs[0]
<br> IPaddr = addr[4][0] <br> return IPaddr #"localhost"</p>
<p> def get_ip(self):<br> return "localhost"</p>
<p> def get_port(self):<br> return 8786</p>
<p> def DealWithReactor(self):<br> now = time.localtime(time.time())<br> factory = pb.PBClientFactory()<br> reactor.connectTCP(self.get_ip(), self.get_port(), factory)<br> d = factory.getRootObject
()<br> strt="hello network " + ' ' + time.asctime(now) <br> d.addCallback(lambda object: object.callRemote("echo", strt))<br> d.addErrback(lambda reason: 'error: '+str(reason.value
))<br> d.addCallback(self.StopReactor)<br> reactor.run()<br> <br> def StopReactor(self,obj): <br> reactor.stop()<br> self.reactorFinished=True<br> self.sText=str(obj)<br>
return obj<br> <br> def testBroker(self):<br> self.reactorFinished=False<br> self.DealWithReactor()<br> while self.reactorFinished==False:<br> pass<br> return 'OK testBroker22
self.reactorFinished:' + str(self.reactorFinished)</p>
<p> def gettestresult(self): <br> return "gettestresult:" + str(self.sText)<br> <br>if __name__=='__main__':<br> import win32com.server.register <br> win32com.server.register.UseCommandLine
(HelloWorld)<br> h=HelloWorld()<br> print(h.gettestresult()) <br> print(h.testBroker())<br> print(h.gettestresult())</p>