<div><br>Hi,</div>
<div>&nbsp;</div>
<div>Apologies, please disregard the previous email - here is the good one.</div>
<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>
<p>Please can you help me to shed some light on this? Should I do it another way? Bellow is the code that I am using.</p>
<p>Many thanks<br>Miguel</p>
<p>----------------------------------------------------<br>The code for the python com client :</p>
<p>import win32com.client<br>object = win32com.client.Dispatch(&quot;Python.TestServer&quot;)<br>print object.gettestresult ()<br>print object.testBroker()<br>print object.gettestresult ()</p>
<p>----------------------------------------------------<br>The code for the VB com client:</p>
<p>Private Sub TestComServer()<br>&nbsp;Dim y As Object<br>&nbsp;Set y = CreateObject(&quot;Python.TestServer&quot;) <br>&nbsp;MsgBox y.gettestresult<br>&nbsp;MsgBox y.testBroker()<br>&nbsp;MsgBox y.gettestresult()<br>&nbsp;Set y = Nothing<br>End Sub
<br>----------------------------------------------------<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>&nbsp;&nbsp;&nbsp; _reg_clsid_ = &quot;{7CC9F362-486D-11D1-BB48-0000E838A65F}&quot;<br>&nbsp;&nbsp;&nbsp; _reg_desc_ = &quot;Python Test COM Server&quot;<br>&nbsp;&nbsp;&nbsp; _reg_progid_ = &quot;Python.TestServer&quot;<br>&nbsp;&nbsp;&nbsp; _public_methods_ = ['testBroker','gettestresult'] 
<br>&nbsp;&nbsp;&nbsp; def __init__(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.sText='sText10'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.reactorFinished=False&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def get_ip(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addrs = socket.getaddrinfo(socket.gethostname(), None)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; addr = addrs[0] 
<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IPaddr = addr[4][0]&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return IPaddr #&quot;localhost&quot;</p>
<p>&nbsp;&nbsp;&nbsp; def get_ip(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return &quot;localhost&quot;</p>
<p>&nbsp;&nbsp;&nbsp; def get_port(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 8786</p>
<p>&nbsp;&nbsp;&nbsp; def DealWithReactor(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; now = time.localtime(time.time())<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; factory = pb.PBClientFactory()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.connectTCP(self.get_ip(), self.get_port(), factory)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d = factory.getRootObject
 ()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; strt=&quot;hello network &quot;&nbsp; + ' ' + time.asctime(now) <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d.addCallback(lambda object: object.callRemote(&quot;echo&quot;, strt))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d.addErrback(lambda reason: 'error: '+str(reason.value
 ))<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; d.addCallback(self.StopReactor)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.run()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def StopReactor(self,obj):&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; reactor.stop()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.reactorFinished=True<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.sText=str(obj)<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return obj<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; def testBroker(self):<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.reactorFinished=False<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.DealWithReactor()<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; while self.reactorFinished==False:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pass<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return 'OK testBroker22 
self.reactorFinished:' + str(self.reactorFinished)</p>
<p>&nbsp;&nbsp;&nbsp; def gettestresult(self):&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return &quot;gettestresult:&quot; + str(self.sText)<br>&nbsp;&nbsp;&nbsp; <br>if __name__=='__main__':<br>&nbsp;&nbsp;&nbsp; import win32com.server.register <br>&nbsp;&nbsp;&nbsp; win32com.server.register.UseCommandLine
 (HelloWorld)<br>&nbsp;&nbsp;&nbsp; h=HelloWorld()<br>&nbsp;&nbsp;&nbsp; print(h.gettestresult())&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; print(h.testBroker())<br>&nbsp;&nbsp;&nbsp; print(h.gettestresult())</p>
<p>&nbsp;</p>