def testall(): dotestall() pythoncom.CoUninitialize() print "AXScript Host worked correctly - %d/%d COM objects left alive." % ( pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount(), )
def test(fn): print "The main thread is %d" % (win32api.GetCurrentThreadId()) GIT = CreateGIT() interp = win32com.client.Dispatch("Python.Interpreter") cookie = GIT.RegisterInterfaceInGlobal(interp._oleobj_, pythoncom.IID_IDispatch) events = fn(4, cookie) numFinished = 0 while 1: try: rc = win32event.MsgWaitForMultipleObjects(events, 0, 2000, win32event.QS_ALLINPUT) if rc >= win32event.WAIT_OBJECT_0 and rc < win32event.WAIT_OBJECT_0 + len(events): numFinished = numFinished + 1 if numFinished >= len(events): break elif rc == win32event.WAIT_OBJECT_0 + len(events): # a message # This is critical - whole apartment model demo will hang. pythoncom.PumpWaitingMessages() else: # Timeout print "Waiting for thread to stop with interfaces=%d, gateways=%d" % ( pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount(), ) except KeyboardInterrupt: break GIT.RevokeInterfaceFromGlobal(cookie) del interp del GIT
def __call__(self, result = None): # Always ensure we don't leak gateways/interfaces gc.collect() ni = _GetInterfaceCount() ng = _GetGatewayCount() self.real_test(result) # Failed - no point checking anything else if result.shouldStop or not result.wasSuccessful(): return self._do_leak_tests(result) gc.collect() lost_i = _GetInterfaceCount() - ni lost_g = _GetGatewayCount() - ng if lost_i or lost_g: msg = "%d interface objects and %d gateway objects leaked" \ % (lost_i, lost_g) result.addFailure(self.real_test, (AssertionError, msg, None))
def CheckClean(): # Ensure no lingering exceptions - Python should have zero outstanding # COM objects sys.exc_clear() c = _GetInterfaceCount() if c: print "Warning - %d com interface objects still alive" % c c = _GetGatewayCount() if c: print "Warning - %d com gateway objects still alive" % c
def __call__(self, result=None): # For the COM suite's sake, always ensure we don't leak # gateways/interfaces from pythoncom import _GetInterfaceCount, _GetGatewayCount gc.collect() ni = _GetInterfaceCount() ng = _GetGatewayCount() self.real_test(result) # Failed - no point checking anything else if result.shouldStop or not result.wasSuccessful(): return self._do_leak_tests(result) gc.collect() lost_i = _GetInterfaceCount() - ni lost_g = _GetGatewayCount() - ng if lost_i or lost_g: msg = "%d interface objects and %d gateway objects leaked" \ % (lost_i, lost_g) exc = AssertionError(msg) result.addFailure(self.real_test, (exc.__class__, exc, None))
def __call__(self, result = None): # For the COM suite's sake, always ensure we don't leak # gateways/interfaces from pythoncom import _GetInterfaceCount, _GetGatewayCount gc.collect() ni = _GetInterfaceCount() ng = _GetGatewayCount() self.real_test(result) # Failed - no point checking anything else if result.shouldStop or not result.wasSuccessful(): return self._do_leak_tests(result) gc.collect() lost_i = _GetInterfaceCount() - ni lost_g = _GetGatewayCount() - ng if lost_i or lost_g: msg = "%d interface objects and %d gateway objects leaked" \ % (lost_i, lost_g) exc = AssertionError(msg) result.addFailure(self.real_test, (exc.__class__, exc, None))
def CheckClean(): # Ensure no lingering exceptions - Python should have zero outstanding # COM objects try: sys.exc_clear() except AttributeError: pass # py3k c = _GetInterfaceCount() if c: print("Warning - %d com interface objects still alive" % c) c = _GetGatewayCount() if c: print("Warning - %d com gateway objects still alive" % c)
def CheckClean(): # Ensure no lingering exceptions - Python should have zero outstanding # COM objects try: sys.exc_clear() except AttributeError: pass # py3k c = _GetInterfaceCount() if c: print("Warning - %d com interface objects still alive" % c) c = _GetGatewayCount() if c: print("Warning - %d com gateway objects still alive" % c)
num = num + 1 finally: win32api.RegCloseKey(key) win32ui.DoWaitCursor(0) ret.sort() return ret def main(): from pywin.tools import hierlist root = HLIRoot("COM Browser") if sys.modules.has_key("app"): # do it in a window browser.MakeTemplate() browser.template.OpenObject(root) else: # list=hierlist.HierListWithItems( root, win32ui.IDB_BROWSER_HIER ) # dlg=hierlist.HierDialog("COM Browser",list) dlg = browser.dynamic_browser(root) dlg.DoModal() if __name__=='__main__': main() ni = pythoncom._GetInterfaceCount() ng = pythoncom._GetGatewayCount() if ni or ng: print "Warning - exiting with %d/%d objects alive" % (ni,ng)
def testall(): dotestall() pythoncom.CoUninitialize() print("AXScript Host worked correctly - %d/%d COM objects left alive." % ( pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()))
events): numFinished = numFinished + 1 if numFinished >= len(events): break elif rc == win32event.WAIT_OBJECT_0 + len(events): # a message # This is critical - whole apartment model demo will hang. pythoncom.PumpWaitingMessages() else: # Timeout print( "Waiting for thread to stop with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount())) except KeyboardInterrupt: break GIT.RevokeInterfaceFromGlobal(cookie) del interp del GIT if __name__ == '__main__': test(BeginThreadsSimpleMarshal) win32api.Sleep(500) # Doing CoUninit here stop Pythoncom.dll hanging when DLLMain shuts-down the process pythoncom.CoUninitialize() if pythoncom._GetInterfaceCount() != 0 or pythoncom._GetGatewayCount( ) != 0: print("Done with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount())) else: print("Done.")
ret.append( HLIRegisteredTypeLibrary((keyName, versionStr), name)) num = num + 1 finally: win32api.RegCloseKey(key) win32ui.DoWaitCursor(0) ret.sort() return ret def main(): from pywin.tools import hierlist root = HLIRoot("COM Browser") if "app" in sys.modules: # do it in a window browser.MakeTemplate() browser.template.OpenObject(root) else: # list=hierlist.HierListWithItems( root, win32ui.IDB_BROWSER_HIER ) # dlg=hierlist.HierDialog("COM Browser",list) dlg = browser.dynamic_browser(root) dlg.DoModal() if __name__ == '__main__': main() ni = pythoncom._GetInterfaceCount() ng = pythoncom._GetGatewayCount() if ni or ng: print("Warning - exiting with %d/%d objects alive" % (ni, ng))
elif medium.tymed==pythoncom.TYMED_MFPICT: data = "METAFILE handle %d" % medium.data elif medium.tymed==pythoncom.TYMED_ENHMF: data = "ENHMETAFILE handle %d" % medium.data elif medium.tymed==pythoncom.TYMED_HGLOBAL: data = "%d bytes via HGLOBAL" % len(medium.data) elif medium.tymed==pythoncom.TYMED_FILE: data = "filename '%s'" % data elif medium.tymed==pythoncom.TYMED_ISTREAM: stream = medium.data stream.Seek(0,0) bytes = 0 while 1: chunk = stream.Read(4096) if not chunk: break bytes += len(chunk) data = "%d bytes via IStream" % bytes elif medium.tymed==pythoncom.TYMED_ISTORAGE: data = "a IStorage" else: data = "*** unknown tymed!" print " -> got", data do = None if __name__=='__main__': DumpClipboard() if pythoncom._GetInterfaceCount()+pythoncom._GetGatewayCount(): print "XXX - Leaving with %d/%d COM objects alive" % \ (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount())
data = "METAFILE handle %d" % medium.data elif medium.tymed == pythoncom.TYMED_ENHMF: data = "ENHMETAFILE handle %d" % medium.data elif medium.tymed == pythoncom.TYMED_HGLOBAL: data = "%d bytes via HGLOBAL" % len(medium.data) elif medium.tymed == pythoncom.TYMED_FILE: data = "filename '%s'" % data elif medium.tymed == pythoncom.TYMED_ISTREAM: stream = medium.data stream.Seek(0, 0) bytes = 0 while 1: chunk = stream.Read(4096) if not chunk: break bytes += len(chunk) data = "%d bytes via IStream" % bytes elif medium.tymed == pythoncom.TYMED_ISTORAGE: data = "a IStorage" else: data = "*** unknown tymed!" print " -> got", data do = None if __name__ == '__main__': DumpClipboard() if pythoncom._GetInterfaceCount() + pythoncom._GetGatewayCount(): print "XXX - Leaving with %d/%d COM objects alive" % \ (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount())
def test(fn): print "The main thread is %d" % (win32api.GetCurrentThreadId()) GIT = CreateGIT() interp = win32com.client.Dispatch("Python.Interpreter") cookie = GIT.RegisterInterfaceInGlobal(interp._oleobj_, pythoncom.IID_IDispatch) events = fn(4, cookie) numFinished = 0 while 1: try: rc = win32event.MsgWaitForMultipleObjects(events, 0, 2000, win32event.QS_ALLINPUT) if rc >= win32event.WAIT_OBJECT_0 and rc < win32event.WAIT_OBJECT_0+len(events): numFinished = numFinished + 1 if numFinished >= len(events): break elif rc==win32event.WAIT_OBJECT_0 + len(events): # a message # This is critical - whole apartment model demo will hang. pythoncom.PumpWaitingMessages() else: # Timeout print "Waiting for thread to stop with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()) except KeyboardInterrupt: break GIT.RevokeInterfaceFromGlobal(cookie) del interp del GIT
events = fn(4, cookie) numFinished = 0 while 1: try: rc = win32event.MsgWaitForMultipleObjects(events, 0, 2000, win32event.QS_ALLINPUT) if rc >= win32event.WAIT_OBJECT_0 and rc < win32event.WAIT_OBJECT_0+len(events): numFinished = numFinished + 1 if numFinished >= len(events): break elif rc==win32event.WAIT_OBJECT_0 + len(events): # a message # This is critical - whole apartment model demo will hang. pythoncom.PumpWaitingMessages() else: # Timeout print("Waiting for thread to stop with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount())) except KeyboardInterrupt: break GIT.RevokeInterfaceFromGlobal(cookie) del interp del GIT if __name__=='__main__': test(BeginThreadsSimpleMarshal) win32api.Sleep(500) # Doing CoUninit here stop Pythoncom.dll hanging when DLLMain shuts-down the process pythoncom.CoUninitialize() if pythoncom._GetInterfaceCount()!=0 or pythoncom._GetGatewayCount()!=0: print("Done with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount())) else: print("Done.")
events = fn(4, cookie) numFinished = 0 while 1: try: rc = win32event.MsgWaitForMultipleObjects(events, 0, 2000, win32event.QS_ALLINPUT) if rc >= win32event.WAIT_OBJECT_0 and rc < win32event.WAIT_OBJECT_0+len(events): numFinished = numFinished + 1 if numFinished >= len(events): break elif rc==win32event.WAIT_OBJECT_0 + len(events): # a message # This is critical - whole apartment model demo will hang. pythoncom.PumpWaitingMessages() else: # Timeout print "Waiting for thread to stop with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()) except KeyboardInterrupt: break GIT.RevokeInterfaceFromGlobal(cookie) del interp del GIT if __name__=='__main__': test(BeginThreadsSimpleMarshal) win32api.Sleep(500) # Doing CoUninit here stop Pythoncom.dll hanging when DLLMain shuts-down the process pythoncom.CoUninitialize() if pythoncom._GetInterfaceCount()!=0 or pythoncom._GetGatewayCount()!=0: print "Done with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()) else: print "Done."
global currentDebugger if currentDebugger is None: currentDebugger = AXDebugger() return currentDebugger def Break(): _GetCurrentDebugger().Break() brk = Break set_trace = Break def dosomethingelse(): a=2 b = "Hi there" def dosomething(): a=1 b=2 dosomethingelse() def test(): Break() raw_input("Waiting...") dosomething() print "Done" if __name__=='__main__': print "About to test the debugging interfaces!" test() print " %d/%d com objects still alive" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount())
global currentDebugger if currentDebugger is None: currentDebugger = AXDebugger() return currentDebugger def Break(): _GetCurrentDebugger().Break() brk = Break set_trace = Break def dosomethingelse(): a=2 b = "Hi there" def dosomething(): a=1 b=2 dosomethingelse() def test(): Break() input("Waiting...") dosomething() print("Done") if __name__=='__main__': print("About to test the debugging interfaces!") test() print(" %d/%d com objects still alive" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()))
def _DoTestMarshal(self, fn, bCoWait = 0): #print "The main thread is %d" % (win32api.GetCurrentThreadId()) threads, events = fn(2) numFinished = 0 while 1: try: if bCoWait: rc = pythoncom.CoWaitForMultipleHandles(0, 2000, events) else: # Specifying "bWaitAll" here will wait for messages *and* all events # (which is pretty useless) rc = win32event.MsgWaitForMultipleObjects(events, 0, 2000, win32event.QS_ALLINPUT) if rc >= win32event.WAIT_OBJECT_0 and rc < win32event.WAIT_OBJECT_0+len(events): numFinished = numFinished + 1 if numFinished >= len(events): break elif rc==win32event.WAIT_OBJECT_0 + len(events): # a message # This is critical - whole apartment model demo will hang. pythoncom.PumpWaitingMessages() else: # Timeout print "Waiting for thread to stop with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()) except KeyboardInterrupt: break for t in threads: t.join(2) self.failIf(t.isAlive(), "thread failed to stop!?") threads = None # threads hold references to args
def _DoTestMarshal(self, fn, bCoWait = 0): #print "The main thread is %d" % (win32api.GetCurrentThreadId()) threads, events = fn(2) numFinished = 0 while 1: try: if bCoWait: rc = pythoncom.CoWaitForMultipleHandles(0, 2000, events) else: # Specifying "bWaitAll" here will wait for messages *and* all events # (which is pretty useless) rc = win32event.MsgWaitForMultipleObjects(events, 0, 2000, win32event.QS_ALLINPUT) if rc >= win32event.WAIT_OBJECT_0 and rc < win32event.WAIT_OBJECT_0+len(events): numFinished = numFinished + 1 if numFinished >= len(events): break elif rc==win32event.WAIT_OBJECT_0 + len(events): # a message # This is critical - whole apartment model demo will hang. pythoncom.PumpWaitingMessages() else: # Timeout print "Waiting for thread to stop with interfaces=%d, gateways=%d" % (pythoncom._GetInterfaceCount(), pythoncom._GetGatewayCount()) except KeyboardInterrupt: break for t in threads: t.join(2) self.failIf(t.isAlive(), "thread failed to stop!?") threads = None # threads hold references to args