473,756 Members | 3,111 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Event-Driven Woes: making wxPython and Twisted work together

Hello,

I am writing an application using two event-driven libraries:
wxPython, and twisted. The first problem I encountered in the program
is the confliction between the two all-consuming methods of the two
libraries: app.MainLoop, and reactor.run. Additionally, the fact that
wxPython was to receive requests from the twisted framework as well as
the end user seemed to be simply asking for trouble.

My initial solution was, naturally, the wxPython support inside of the
twisted framework. However, it has been documented by the author that
the support is unstable at this time, and should not be used in
full-scale applications. I instinctively turned to threading, however
on top of the trouble that this has caused on its own, it has
repeatedly been suggested by the twisted IRC channel not to do this.
After much dwelling on the issue, I have resolved to turn to c.l.py,
to see if anyone had a solution to this problem.

Any help would be very much appreciated,

Daniel Bickett
Jul 18 '05 #1
2 2764
Hi Daniel,

I went down that road for a long time. I made a recipe to help people
out:

http://aspn.activestate.com/ASPN/Coo.../Recipe/286201

Don't be intimidated by the size, that's a whole demo app complete with
gui. It works quite well. It uses two threads, wx runs in the main
thread and twisted runs in the second thread.

You'll probably just want to glean solutions from it and write your own
framework. It does still have some hicups!

I gave up trying to perfectionalise it and switched to pygtk, glade and
libglade.

pygtk runs fine on both linux and windows, and you get a gui designer.
The only downside is that it has less widgets. It has the advantage of
themes though, this means on windows you can make it look like windows,
linux, mac or whatever. Also your app will load faster than a wx app.
Unfortunately it does take up more disk space though.

Anyway to make wx and twisted work together, put twisted in a secondary
thread. I tried making them co-exist in a single thread as some other
recipes suggest, but basically modal dialogs don't seem to work
properly.

This recipe might be an easier solution for you. Haven't tried it
though:

http://aspn.activestate.com/ASPN/Coo.../Recipe/203471
God Bless

Jul 18 '05 #2
Daniel Bickett <db******@gmail .com> writes:
My initial solution was, naturally, the wxPython support inside of the
twisted framework. However, it has been documented by the author that
the support is unstable at this time, and should not be used in
full-scale applications.


Rather than the wx reactor, there's an alternate recipe that just
cranks the twisted event loop from within a timer at the wx level that
we've used very successfully. It does have some caveats (such as a
potentially higher latency in servicing the network based on your
timer interval), but so far for our applications it hasn't been an
issue at all, so it might be something you might try. The code was
based on http://aspn.activestate.com/ASPN/Coo.../Recipe/181780

The advantage of this approach is that no threads are necessary, and
thus there's no problem issuing wxPython calls from within twisted
callbacks or twisted calls from within wxPython event handlers.

Just include the following bits into your application object (note that
the use of "installSignalH andlers" might not be needed on all systems):

class MyApp(wx.wxApp) :

(...)

def OnInit(self):

# Twisted Reactor code
reactor.startRu nning(installSi gnalHandlers=0)
wx.EVT_TIMER(se lf, 999999, self.OnTimer)
self.timer = wx.wxTimer(self , 999999)
self.timer.Star t(150, False)

(...)

def OnTimer(self, event):
reactor.runUnti lCurrent()
reactor.doItera tion(0)

def __del__(self):
self.timer.Stop ()
reactor.stop()
wx.wxApp.__del_ _(self)
and you can try adjusting the timer interval for the best mix of CPU
load versus latency.

-- David
Jul 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
49581
by: Pavils Jurjans | last post by:
Hallo, I have been programming for restricted environments where Internet Explorer is a standard, so I haven't stumbled upon this problem until now, when I need to write a DOM-compatible code. The question is about best practices for passing parameters to an event function. I have, say, the following HTML:
8
6087
by: Mark | last post by:
Hi, I'm looking for some ideas on how to build a very simple Event processing framework in my C++ app. Here is a quick background ... I'm building a multithreaded app in C++ (on Linux) that uses message queues to pass pointers to Events between threads. In my app there are simple events that can be defined using an enum (for example an event called NETWORK_TIMEOUT) and more complex events that contain data (for example an event called...
3
2733
by: Marcia Gulesian | last post by:
How can I capture the event when I click (focus) with the cursor anywhere in the page (that is, on a component or elsewhere). This event would occur in an I.E 5.5 or later browser.
3
12151
by: Melissa | last post by:
What specifically causes the Format event of a report's section to fire? Thanks! Melissa
2
4990
by: Alex Sedow | last post by:
Why interface-event-declaration does not support multiple declarators like event-declaration? Grammar from C# spec: variable-declarators: variable-declarator variable-declarators "," variable-declarator variable-declarator:
7
390
by: Charles Law | last post by:
I may have asked this before, but what is the purpose of both these functions? Is there a time when one should be called over the other? Does one supersede the other, or do they both have their time and place? TIA Charles
0
2075
by: Kamilche | last post by:
''' event.py An event manager using publish/subscribe, and weakrefs. Any function can publish any event without registering it first, and any object can register interest in any event, even if it doesn't exist yet. The event manager uses weakrefs, so lists of listeners won't stop them
9
2471
by: jeff | last post by:
New VB user...developer... Situation...simplified... - I want to wrap a pre and post event around a system generated where the pre-event will always execute before the system event and the post event will always execuate after the system is completed... - I want to wrap this functionality in a framework, so I could possibly have 3 or 4 levels of inherited objects that need to have these pre / post events executed before and after the...
19
4757
by: Daniela Roman | last post by:
Hello, I try to fire an event under a button click event and maybe anybody can give a clue please. I have let's say a WEB grid with PageIndexChanged event: private void DataGrid1_PageIndexChanged(object source, System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
4
237
by: tshad | last post by:
I am just getting started with events and had a couple of questions on why they do what they do. If you have a textbox and you want to handle an event you can just do: this.TextBox2.TextChanged += new EventHandler(TextBox2_TextChanged); and then have the function. void TextBox2_TextChanged(object sender, EventArgs e)
0
9325
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9152
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9716
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9716
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9571
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7116
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4996
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5180
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3676
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.