TraceCollector.py :  » Windows » pyExcelerator » pywin32-214 » pythonwin » pywin » tools » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Windows » pyExcelerator 
pyExcelerator » pywin32 214 » pythonwin » pywin » tools » TraceCollector.py
# win32traceutil like utility for Pythonwin
import thread
import win32trace, win32event, win32api
from pywin.framework import winout

outputWindow = None

def CollectorThread(stopEvent, file):
  win32trace.InitRead()
  handle = win32trace.GetHandle()
  # Run this thread at a lower priority to the main message-loop (and printing output)
  # thread can keep up
  import win32process
  win32process.SetThreadPriority(win32api.GetCurrentThread(), win32process.THREAD_PRIORITY_BELOW_NORMAL)

  try:
    while 1:
      rc = win32event.WaitForMultipleObjects((handle, stopEvent), 0, win32event.INFINITE)
      if rc == win32event.WAIT_OBJECT_0:
        # About the only char we can't live with is \0!
        file.write(win32trace.read().replace("\0", "<null>"))
      else:
        # Stop event
        break
  finally:
    win32trace.TermRead()
    print "Thread dieing"

class WindowOutput(winout.WindowOutput):
  def __init__(self, *args):
    winout.WindowOutput.__init__(*(self,)+args)
    self.hStopThread = win32event.CreateEvent(None, 0, 0, None)
    thread.start_new(CollectorThread, (self.hStopThread, self))
  def _StopThread(self):
    win32event.SetEvent(self.hStopThread)
    self.hStopThread = None
  def Close(self):
    self._StopThread()
    winout.WindowOutput.Close(self)
#  def OnViewDestroy(self, frame):
#    return winout.WindowOutput.OnViewDestroy(self, frame)
#  def Create(self, title=None, style = None):
#    rc = winout.WindowOutput.Create(self, title, style)
    return rc
    

def MakeOutputWindow():
  # Note that it will not show until the first string written or
  # you pass bShow = 1
  global outputWindow
  if outputWindow is None:
    title = "Python Trace Collector"
    # queueingFlag doesnt matter, as all output will come from new thread
    outputWindow = WindowOutput(title, title)
    # Let people know what this does!
    msg = """\
# This window will display output from any programs that import win32traceutil
# win32com servers registered with '--debug' are in this category.
"""
    outputWindow.write(msg)
  # force existing window open
  outputWindow.write('')
  return outputWindow

if __name__=='__main__':
  MakeOutputWindow()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.