Here's my win32guireactor code, which at least for me, works better than win32eventreactor in my application. I have some problems in my app when using win32eventreactor: If the app displays a message box, no callLater calls are done (because a win32 messagebox has it's own event loop, and doIteration() is not called during this time. There are also other things that the user can do which shows the same behaviour, dragging a scrollbar for example. The second problem is that win32eventreactor uses a lot a cpu time - nearly 100% even on my brandnew 2GHz P4. Looks much like polling behaviour instead of event driven. So I wrote my own reactor implementation, which passes all events (those I've covered so far, reactor.callLater and network events) through a win32 message loop. Deferred's are not yet passed through the loop, so there is still some polling to be done. Looking at the comments at the top of the win32eventreactor code, my win32guireactor module shouldn't have the problems mentioned there. I post this module here asking for peer review and critical comments. This module requires win32all and my ctypes module as well, see the source for details. Thanks, Thomas PS: I tried to run unittests with this and other reactors with the command line py22 bin\trial -p twisted.test.test_internet -r <reactor> -v here are the results: default reactor FAILED (failures=5, errors=18) win32eventreactor twisted.test.test_ftp:FTPClientAndServerTests.testLongFileListings hangs forver. win32guireactor twisted.test.test_ftp:FTPClientAndServerTests.testLongFileListings crashes with this traceback, and then also hangs forever. twisted.test.test_ftp FTPClientAndServerTests testBadLogin ... testLongFileListings ... Traceback (most recent call last): File "C:\sf\Twisted\twisted\internet\win32guireactor.py", line 85, in __wm_timerevent tple.func(*tple.args, **tple.kw) File "C:\sf\Twisted\twisted\test\test_ftp.py", line 124, in errback except self.failureException, e: AttributeError: FTPClientAndServerTests instance has no attribute 'failureException'
On Fri, Feb 14, 2003 at 04:10:24PM +0100, Thomas Heller wrote: [..snip cool stuff about a win32 reactor that doesn't suck as much..] As the person who wrote the original prototype of the win32 reactor, I'd just like to say: You rock!
PS: I tried to run unittests with this and other reactors with the command line py22 bin\trial -p twisted.test.test_internet -r <reactor> -v
You probably should try py22 bin\trial -p twisted.test -r <reactor> -v as well, i.e. *all* of the tests.
win32guireactor twisted.test.test_ftp:FTPClientAndServerTests.testLongFileListings crashes with this traceback, and then also hangs forever. twisted.test.test_ftp FTPClientAndServerTests testBadLogin ... testLongFileListings ... Traceback (most recent call last): File "C:\sf\Twisted\twisted\internet\win32guireactor.py", line 85, in __wm_timerevent tple.func(*tple.args, **tple.kw) File "C:\sf\Twisted\twisted\test\test_ftp.py", line 124, in errback except self.failureException, e: AttributeError: FTPClientAndServerTests instance has no attribute 'failureException'
Ooh! That's a trial bug -- pyunit TestCases have a "failureException" attribute... by default I think it's set to AssertionError.
"""A win32 implementation of the Twisted main loop.
[snip] Interesting. I don't have a win32 system I can play with this stuff on anymore, but you obviously have more of an idea about win32 programming than I did :) -Andrew.
Thomas Heller <theller@python.net> writes:
Here's my win32guireactor code, which at least for me, works better than win32eventreactor in my application.
Just in case this code is used by anyone, I just fixed two bugs. Thomas
def __wm_timerevent(self, hwnd, msg, wParam, lParam): # This method is called if the message window receives # timer events user32.KillTimer(hwnd, wParam) tple = self.timers[wParam]
del self.timers[wParam]
tple.func(*tple.args, **tple.kw)
def _cancelCallLater(self, tple): user32.KillTimer(self.__hwnd, tple._timerid) del self.timers[tple._timerid]
try: del self.timers[tple._timerid] except KeyError: pass
participants (2)
-
Andrew Bennetts
-
Thomas Heller