[Twisted-Python] Newbie question
![](https://secure.gravatar.com/avatar/af990154952d9fe7e026da2c56ad45aa.jpg?s=120&d=mm&r=g)
Gentlemen: Thanks for all your responses. I think a restartable reactor is a great idea! In the meantime, here is what I am really trying to do. I have a server running a perspective broker, doing its select loop. I need to access that server from a client that is not in a select loop. The client wants to treat the server as if it were an ordinary rpc -- make the call and get the response synchronously, and go away. Then later on it will come back later and call the server again. Is it possible to use twisted servers with "ordinary" clients? -- perplexed
![](https://secure.gravatar.com/avatar/10aa56aec887e973085025c6ddfdc46b.jpg?s=120&d=mm&r=g)
On Mon, 11 Sep 2006 11:11:58 -0400, Stan Benrsteen <sbernste@mitre.org> wrote:
Is it possible to use twisted servers with "ordinary" clients?
nope :). You should really use twisted also on the client side, it can work with all the major GUI toolkits available without many problems.
![](https://secure.gravatar.com/avatar/d6328babd9f9a98ecc905e1ccac2495e.jpg?s=120&d=mm&r=g)
On Mon, 11 Sep 2006 11:11:58 -0400, Stan Benrsteen <sbernste@mitre.org> wrote:
Thanks for all your responses. I think a restartable reactor is a great idea!
I look forward to your patches :)
Is it possible to use twisted servers with "ordinary" clients?
Yes, in the sense that you can easily connect a "regular" client to a Twisted server. No, in the sense that you want, which is to say you shouldn't use a blocking client within the Twisted main loop. However, as dialtone said, it should be easy enough to write a non-blocking client; twisted's client support is just as good as its server support :)
![](https://secure.gravatar.com/avatar/71d29415b83286c89479f05f4e696b2d.jpg?s=120&d=mm&r=g)
On 9/11/06, glyph@divmod.com <glyph@divmod.com> wrote:
However, as dialtone said, it should be easy enough to write a non-blocking client; twisted's client support is just as good as its server support :)
Of course, sometimes this isn't possible at all (you're embedded in a closed source application, etc). The general answer is you need twisted's loop running on another thread or in another process and you need to make calls across this. A simple way is to spawn the reactor in a separate thread (IIRC not all reactors are safe to run on a thread other than the main one, check with someone more knowledgeable) and use the threadsafe built-in queue to push requests across (you just do a blocking pop on the "output" queue and you have the blocking semantics you wish, but this part is optional). This isn't a common use case for me, so there may be better or built-in ways of doing this. To summarize, Glyph and Dialtone are right, if you can rewrite you definitely should, but if you can't there are ways around it.
participants (4)
-
glyph@divmod.com
-
Stan Benrsteen
-
Timothy Fitz
-
Valentino Volonghi aka Dialtone