[Twisted-Python] Connect to a Perspective Broker from a VB App(using a python com server) (Pls disrigard previous one)

Hermínio Miguel Sanches hsanches at gmail.com
Wed Aug 23 09:38:11 EDT 2006


Apologies, please disregard the previous email - here is the good one.

I need to connect to a PerspectiveBroker from a VB application.
I did it with a com server in python, which works fine when the com client
is also python code.
All the calls must be synchronous to the com server.
When Calling from VB it works fine every time if the function used from the
com server don't use the reactor.

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.
The function from the test code is: testBroker()

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.

Many thanks

The code for the python com client :

import win32com.client
object = win32com.client.Dispatch("Python.TestServer")
print object.gettestresult ()
print object.testBroker()
print object.gettestresult ()

The code for the VB com client:

Private Sub TestComServer()
 Dim y As Object
 Set y = CreateObject("Python.TestServer")
 MsgBox y.gettestresult
 MsgBox y.testBroker()
 MsgBox y.gettestresult()
 Set y = Nothing
End Sub
the code for the python comserver:

from twisted.spread import pb
from twisted.internet import reactor, defer
from twisted.python import util
import sys
import time
import socket

class HelloWorld:
    _reg_clsid_ = "{7CC9F362-486D-11D1-BB48-0000E838A65F}"
    _reg_desc_ = "Python Test COM Server"
    _reg_progid_ = "Python.TestServer"
    _public_methods_ = ['testBroker','gettestresult']
    def __init__(self):
    def get_ip(self):
        addrs = socket.getaddrinfo(socket.gethostname(), None)
        addr = addrs[0]
        IPaddr = addr[4][0]
        return IPaddr #"localhost"

    def get_ip(self):
        return "localhost"

    def get_port(self):
        return 8786

    def DealWithReactor(self):
        now = time.localtime(time.time())
        factory = pb.PBClientFactory()
        reactor.connectTCP(self.get_ip(), self.get_port(), factory)
        d = factory.getRootObject ()
        strt="hello network "  + ' ' + time.asctime(now)
        d.addCallback(lambda object: object.callRemote("echo", strt))
        d.addErrback(lambda reason: 'error: '+str(reason.value ))

    def StopReactor(self,obj):
        return obj

    def testBroker(self):
        while self.reactorFinished==False:
        return 'OK testBroker22 self.reactorFinished:' + str(

    def gettestresult(self):
        return "gettestresult:" + str(self.sText)

if __name__=='__main__':
    import win32com.server.register
    win32com.server.register.UseCommandLine (HelloWorld)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20060823/a298c271/attachment.htm 

More information about the Twisted-Python mailing list