[Twisted-Python] reactor and thread

Michele Petrazzo - Unipex srl michele.petrazzo at unipex.it
Wed Jun 13 14:21:10 EDT 2007


Hi all,
I have a project where I writing the "server" (on win xp) and I want to
communicate with a client, so twisted it's all I need.
Into the "server" I have also a python bind to a dll (with ctypes) and I
see strange problems (windows crashes) when I call a dll function inside
a thread. My thread it's a twisted "Protocol".
My question is: it is possible to call the function from/to a specific
thread? So somethink like:

class MyDll:
  def funct(self, callBack):
    #do the work
    reactor.call_in_main_thrad(callBack)


tid = create_a_thread_and_load_MyDll() # where I make the dll instance
and all the work need into a thread

#into a someone function into the main thread

def callBack():
  # a simple callback

reactor.callIntoThread(tid, funct, callBack)

Is this possible with twisted? (Does I'm dreaming?)

P.s. If I try with the wx "reactor" (so wx.MainLoop), I see no problem!
In that case, I instance the dll into the class __init__ (inherit from
wx.Frame) and into a someone event (i.e. Button click) I call a dll
funct and all work without crash...

Thanks,
Michele
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 3273 bytes
Desc: S/MIME Cryptographic Signature
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20070613/cc93ce9c/attachment.bin 


More information about the Twisted-Python mailing list