[python-win32] ReadEventLog doesn't return, CPU usage increases

Jeff Quandt Jeff.Quandt at bhmi.com
Thu Mar 2 23:42:39 CET 2006


This is running Python 2.3 on windows 2003/windows xp.

I have written a script to display and filter the Win32 event log in a scrolling list to the command line (it also does some summary tasks).  It uses the win32evtlog.ReadEventLog to seek or scan the event log based on filter parameters.  It is supposed to run until the user kills it, so there are repeated calls to ReadEventLog.  

The problem is that after the script has run from some time (usually several hours), the call to ReadEventLog seems to hang and the CPU usage increases dramatically (from nil to 30-50%).  The script does not exit this stage, and has to be broken manually with Ctrl-C.  I've tried closing and reopening the event log handle after it has been open for an hour.  I've added explicit calls to the garbage collector.  Neither helped at all.

I realize that this is an API call, so it may not be a python issue.  But I have seen this type of behavior on other scripts (not event loggers), but they were test/debug tools and weren't important enough to track down the issue.

Any help would be appreciated.

code example:

    def OpenLog( self ):
        #
        #open event log
        #
        self.mHandle              = win32evtlog.OpenEventLog( self.mComputer
                                                            , self.mLogType
                                                            )
        if not self.mHandle:
            raise ValueError, "invalid handle"

        self.mLogOpenTmst = time.time()

    def CloseLog( self ):

        win32evtlog.CloseEventLog( self.mHandle     )

    def ReadLog( self ):

	self.mFlags = win32evtlog.EVENTLOG_FORWARDS_READ|win32evtlog.EVENTLOG_SEEK_READ
            vEventScon  = win32evtlog.ReadEventLog( self.mHandle
                                                  , self.mFlags
                                                  , self.mLogOffset
                                                  )
            #
            # if not found, try again in 5 seconds
            #
            if not vEventScon:

                #
                # If we've had the log open for more than 1 hour, dump it and reopen
                #
                if ( time.time() > (self.mLogOpenTmst + 3600) ):
                    self.CloseLog()
                    self.OpenLog()

                time.sleep( 5 )
                return bOk

	#
	# snip...
	# manipulate event records here
	#

#
# main
#
OpenLog
Ok = 1
while Ok:
	Ok = ReadLog()
CloseLog()



-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/python-win32/attachments/20060302/ee811f53/attachment.html 


More information about the Python-win32 mailing list