plexpy/lib/pythonwin/pywin/tools/TraceCollector.py
dependabot[bot] faef9a94c4
Bump cherrypy from 18.8.0 to 18.9.0 (#2266)
* Bump cherrypy from 18.8.0 to 18.9.0

Bumps [cherrypy](https://github.com/cherrypy/cherrypy) from 18.8.0 to 18.9.0.
- [Changelog](https://github.com/cherrypy/cherrypy/blob/main/CHANGES.rst)
- [Commits](https://github.com/cherrypy/cherrypy/compare/v18.8.0...v18.9.0)

---
updated-dependencies:
- dependency-name: cherrypy
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>

* Update cherrypy==18.9.0

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: JonnyWong16 <9099342+JonnyWong16@users.noreply.github.com>

[skip ci]
2024-03-24 15:25:44 -07:00

79 lines
2.4 KiB
Python

# win32traceutil like utility for Pythonwin
import _thread
import win32api
import win32event
import win32trace
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()