[Twisted-Python] Twistd .tac + wxpython
Hello everyone, I have some services written that I'd like to run in a ta.c w/ twistd. One of them uses wxpython. I originally used the wxreactor but it seams to have some problems on Mac OS X and Windows, so with help from some people on this list I ended up using the wx mainloop as the mainloop and putting the reactor in a separate thread. This seams to work well, but now that I want to create a .tac I don't think this is possible. The problem that prompted me to create a .tac is that if I want to use py2app, I need just one main file and my app works using a launcher that accepts a service name as a param and it takes care of running it. On Windows with py2exe, I had created a main script that called the launcher with the param in a new process. Py2exe is capable of creating several .exe files, so I would generate the launcher and the main script. Not being able to do this with py2app I though of ditching my launcher and using twistd. Even in the event that I got everything to work with the wx reactor, from what I understand twistd uses one reactor (that can be specified via command-line), and thus I would either have to use the wxreactor for all the services (which doesn't work), or a standard reactor, but then it's my wx service that won't work. I thought of maybe putting the wx mainloop in a thread and using the standard reactor but I don't know how well this works or even if it's possible. Does anyone have an idea? I'm open to all suggestions and proposals, Gabriel
Hi Gabriel, On Thu, Aug 20, 2009 at 5:20 AM, Gabriel Rossetti < gabriel.rossetti@arimaz.com> wrote:
I thought of maybe putting the wx mainloop in a thread and using the standard reactor but I don't know how well this works or even if it's possible.
If you've already got all the appropriate code to separate out the GUI into a separate thread and communicate with the networking components via message queues, then this should work just fine. Normally I'd suspect wx (which I find to be a highly idiosyncratic, buggy, and arbitrarily limited library: have you considered using something else for your GUI?) might have some difficulties that I'm not aware of, but I'm pretty sure several other Twisted users have already done this exact type of integration. Personally, regardless of UI toolkit, in this situation I'd have the server start up with a "normal" reactor (select, poll, epoll, kqueue: take your pick) and have it spawn a separate GUI process with the GUI reactor, and communicate via a socket. That way the GUI can be shut down and restarted without killing the back-end, and the back-end could be moved to a different machine. But I don't know a lot about your application and there may be some requirements I'm not aware of :).
One of them uses wxpython. I originally used the wxreactor but it seams to have some problems on Mac OS X and Windows, so with help from some
I've used wxreactor the same way as John and used py2exe on Windows and cxFreeze and PyInstaller on Linux to crate a single executable file. This was a client with a GUI and I've not used twistd. What problems do you have with wxreactor?
Windows with py2exe, I had created a main script that called the launcher with the param in a new process. Py2exe is capable of creating several .exe files, so I would generate the launcher and the main script. Not being able to do this with py2app I though of ditching my launcher and using twistd. Even in the event that I got everything to work with the wx reactor, from what I understand twistd uses one reactor
In completely different app (a server without GUI) I needed a part of the functionality provided by twistd and at the same time the possibility to crate a single file executable. I ended subclassing ProcessOption and ApplicationRunner as Jared recommended here http://twistedmatrix.com/pipermail/twisted-python/2009-July/019917.html Regards, Mikhail
Hi Glyph,
Glyph Lefkowitz
If you've already got all the appropriate code to separate out the GUI into a
separate thread and communicate with the networking components via message queues, then this should work just fine. Normally I'd suspect wx (which I find to be a highly idiosyncratic, buggy, and arbitrarily limited library: have you considered using something else for your GUI?) might have some difficulties that I'm not aware of, but I'm pretty sure several other Twisted users have already done this exact type of integration.
What GUI library would you recommend instead of wx? Regards, Mikhail
On 09:00 pm, termim@gmail.com wrote:
Hi Glyph,
Glyph Lefkowitz
writes: If you've already got all the appropriate code to separate out the GUI into a
separate thread and communicate with the networking components via message queues, then this should work just fine. �Normally I'd suspect wx (which I find to be a highly idiosyncratic, buggy, and arbitrarily limited library: have you considered using something else for your GUI?) might have some difficulties that I'm not aware of, but I'm pretty sure several other Twisted users have already done this exact type of integration.
What GUI library would you recommend instead of wx?
Gtk2 is significantly more well integrated with Twisted (because it's significantly easier to integrate with, although many Twisted developers also rather like it apart from that fact). Jean-Paul
Glyph Lefkowitz wrote:
Hi Gabriel,
On Thu, Aug 20, 2009 at 5:20 AM, Gabriel Rossetti
mailto:gabriel.rossetti@arimaz.com> wrote: I thought of maybe putting the wx mainloop in a thread and using the standard reactor but I don't know how well this works or even if it's possible.
If you've already got all the appropriate code to separate out the GUI into a separate thread and communicate with the networking components via message queues, then this should work just fine. Normally I'd suspect wx (which I find to be a highly idiosyncratic, buggy, and arbitrarily limited library: have you considered using something else for your GUI?) might have some difficulties that I'm not aware of, but I'm pretty sure several other Twisted users have already done this exact type of integration.
Personally, regardless of UI toolkit, in this situation I'd have the server start up with a "normal" reactor (select, poll, epoll, kqueue: take your pick) and have it spawn a separate GUI process with the GUI reactor, and communicate via a socket. That way the GUI can be shut down and restarted without killing the back-end, and the back-end could be moved to a different machine. But I don't know a lot about your application and there may be some requirements I'm not aware of :).
Hi Glyph, I have 3 versions of my code, one using wxreactor, one where the mainloop is wx's and Twisted's reactor is in a thread, and one where it's Twisted's reactor as the mainloop and wx is in a thread. To answer your question, originally I considered pyQT but when I saw that it wasn't free I changed my mind. pyGTK, the problem is the integration in different OSes, I need great integration in Linux, Mac OS X and Windows and GTK apps don't do that as well. Yes, that is what I ended up doing :-) Cheers, Gabriel
participants (5)
-
David Ripton
-
exarkun@twistedmatrix.com
-
Gabriel Rossetti
-
Glyph Lefkowitz
-
Mikhail