コード例 #1
0
    def testInitTermRead(self):
        self.assertRaises(win32trace.error, win32trace.read)
        win32trace.InitRead()
        result = win32trace.read()
        self.assertEqual(result, "")
        win32trace.TermRead()
        self.assertRaises(win32trace.error, win32trace.read)

        win32trace.InitRead()
        self.assertRaises(win32trace.error, win32trace.InitRead)
        win32trace.InitWrite()
        self.assertRaises(win32trace.error, win32trace.InitWrite)
        win32trace.TermWrite()
        win32trace.TermRead()
コード例 #2
0
ファイル: test_win32trace.py プロジェクト: beiske/play
 def setUp(self):
     win32trace.InitRead()
     # If any other writers are running (even if not actively writing),
     # terminating the module will *not* close the handle, meaning old data
     # will remain. This can cause other tests to fail.
     win32trace.read()
     win32trace.InitWrite()
コード例 #3
0
ファイル: test_win32trace.py プロジェクト: beiske/play
 def setUp(self):
     win32trace.InitRead()
     TraceWriteProcess.BucketCount = self.BucketCount
     self.setUpWriters()
     self.buckets = range(self.BucketCount)
     for each in self.buckets:
         self.buckets[each] = 0
コード例 #4
0
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")
コード例 #5
0
    def testInitTermRead(self):
        with pytest.raises(win32trace.error):
            win32trace.read()
        win32trace.InitRead()
        result = win32trace.read()
        assert result == ''
        win32trace.TermRead()
        with pytest.raises(win32trace.error):
            win32trace.read()

        win32trace.InitRead()
        with pytest.raises(win32trace.error):
            win32trace.InitRead()
        win32trace.InitWrite()
        with pytest.raises(win32trace.error):
            win32trace.InitWrite()
        win32trace.TermWrite()
        win32trace.TermRead()
コード例 #6
0
ファイル: test_win32trace.py プロジェクト: beiske/play
 def setUp(self):
     WriterThread.BucketCount = self.BucketCount        
     win32trace.InitRead()
     win32trace.read() # clear any old data.
     win32trace.InitWrite()
     CheckNoOtherReaders()
     self.threads = [WriterThread() for each in range(self.FullBucket)]
     self.buckets = range(self.BucketCount)
     for each in self.buckets:
         self.buckets[each] = 0
コード例 #7
0
ファイル: test_win32trace.py プロジェクト: beiske/play
 def testInit(self):
     win32trace.TermRead()
     win32trace.TermWrite()
     traceObject = win32trace.GetTracer()
     self.assertRaises(win32trace.error, traceObject.read)
     self.assertRaises(win32trace.error, traceObject.write, '')
     win32trace.InitRead()
     win32trace.InitWrite()
     self.assertEquals('', traceObject.read())
     traceObject.write('Syver')
コード例 #8
0
ファイル: test_win32trace.py プロジェクト: beiske/play
    def testTermSematics(self):
        win32trace.InitWrite()
        win32trace.write('Ta da')

        # if we both Write and Read are terminated at the same time,
        # we lose the data as the win32 object is closed.  Note that
        # if another writer is running, we do *not* lose the data - so
        # test for either the correct data or an empty string
        win32trace.TermWrite()
        win32trace.InitRead()
        self.failUnless(win32trace.read() in ['Ta da', ''])
        win32trace.TermRead()

        # we keep the data because we init read before terminating write
        win32trace.InitWrite()
        win32trace.write('Ta da')
        win32trace.InitRead()
        win32trace.TermWrite()
        self.assertEquals('Ta da', win32trace.read())
        win32trace.TermRead()
コード例 #9
0
 def testInit(self):
     win32trace.TermRead()
     win32trace.TermWrite()
     traceObject = win32trace.GetTracer()
     with pytest.raises(win32trace.error):
         traceObject.read()
     with pytest.raises(win32trace.error):
         traceObject.write('')
     win32trace.InitRead()
     win32trace.InitWrite()
     assert '' == traceObject.read()
     traceObject.write('Syver')
コード例 #10
0
ファイル: win32traceutil.py プロジェクト: sriram90/arangodb
def RunAsCollector():
    import sys
    try:
        import win32api
        win32api.SetConsoleTitle("Python Trace Collector")
    except:
        pass  # Oh well!
    win32trace.InitRead()
    print "Collecting Python Trace Output..."
    #	import win32api;win32api.DebugBreak()
    while 1:
        #		print win32trace.blockingread()
        sys.stdout.write(win32trace.blockingread())
コード例 #11
0
def RunAsTraceCollector():
    import sys
    try:
        import win32api
        win32api.SetConsoleTitle("Python Trace Collector")
    except:
        pass  # Oh well!
    win32trace.InitRead()
    p("Collecting Python Trace Output...", log_level=4)
    try:
        while 1:
            # a short timeout means ctrl+c works next time we wake...
            sys.stdout.write(win32trace.blockingread(500))
    except KeyboardInterrupt:
        p("}}ybCtrl+C - quitting...}}xx", log_level=3)
コード例 #12
0
def RunAsCollector():
    import sys
    try:
        import win32api
        win32api.SetConsoleTitle("Python Trace Collector")
    except:
        pass  # Oh well!
    win32trace.InitRead()
    print("Collecting Python Trace Output...")
    try:
        while True:
            # a short timeout means ctrl+c works next time we wake...
            sys.stdout.write(win32trace.blockingread(500))
    except KeyboardInterrupt:
        print("Ctrl+C")
コード例 #13
0
ファイル: test_win32trace.py プロジェクト: beiske/play
 def setUp(self):
     # clear old data
     win32trace.InitRead()
     win32trace.read()
     win32trace.TermRead()
コード例 #14
0
ファイル: test_win32trace.py プロジェクト: beiske/play
 def setUp(self):
     win32trace.InitRead()
     win32trace.read() # clear any old data
     win32trace.InitWrite()
コード例 #15
0
ファイル: test_win32trace.py プロジェクト: beiske/play
            assert each.verifyWritten()
        assert self.areBucketsFull()    

def _RunAsTestProcess():
    # Run as an external process by the main tests.
    WriterThread.BucketCount = int(sys.argv[2])
    threadCount = int(sys.argv[3])
    threads = [WriterThread() for each in range(threadCount)]
    win32trace.InitWrite()
    for thread in threads:
        thread.start()
    for thread in threads:
        thread.join()
    for thread in threads:
        if not thread.verifyWritten():
            sys.exit(-1)
    
if __name__ == '__main__':
    if sys.argv[1:2]==["/run_test_process"]:
        _RunAsTestProcess()
        sys.exit(0)
    # If some other win32traceutil reader is running, these tests fail
    # badly (as the other reader sometimes sees the output!)
    win32trace.InitRead()
    win32trace.InitWrite()
    CheckNoOtherReaders()
    # reset state so test env is back to normal
    win32trace.TermRead()
    win32trace.TermWrite()
    unittest.main()