Changeset 69574 in vbox
- Timestamp:
- Nov 4, 2017 8:52:53 AM (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/testdriver/vbox.py
r69562 r69574 1448 1448 import gc; 1449 1449 1450 # Drop all references we've have to COM objects. 1450 1451 self.aoRemoteSessions = []; 1451 1452 self.aoVMs = []; … … 1455 1456 self.checkProcessHeap(); ## TEMPORARY 1456 1457 1458 # Do garbage collection to try get rid of those objects. 1457 1459 try: 1458 1460 gc.collect(); 1459 aObjects = gc.get_objects();1460 try:1461 try: from types import InstanceType; # For old-style python 2.x objects, not in python 3.1462 except ImportError: InstanceType = None;1463 for oObj in aObjects:1464 oObjType = type(oObj)1465 if oObjType == InstanceType: # Python 2.x codepath1466 oObjType = oObj.__class__1467 if oObjType.__name__ == 'VirtualBoxManager':1468 reporter.log('actionCleanupAfter: CAUTION, there is still a VirtualBoxManager object, GC trouble')1469 break1470 finally:1471 del aObjects;1472 1461 except: 1473 1462 reporter.logXcpt(); … … 1475 1464 self.checkProcessHeap(); ## TEMPORARY 1476 1465 1466 # Check whether the python is still having any COM objects/interfaces around. 1467 cVBoxMgrs = 0; 1468 aoObjsLeftBehind = []; 1477 1469 if self.sHost == 'win': 1470 import pythoncom; # pylint: disable=import-error 1478 1471 try: 1479 import pythoncom; # pylint: disable=import-error 1480 cIfs = pythoncom._GetInterfaceCount(); # pylint: disable=no-member,protected-access 1481 cObjs = pythoncom._GetGatewayCount(); # pylint: disable=no-member,protected-access 1472 cIfs = pythoncom._GetInterfaceCount(); # pylint: disable=no-member,protected-access 1473 cObjs = pythoncom._GetGatewayCount(); # pylint: disable=no-member,protected-access 1482 1474 if cObjs == 0 and cIfs == 0: 1483 reporter.log(' actionCleanupAfter: no interfaces or objects left behind.');1475 reporter.log('_teardownVBoxApi: no interfaces or objects left behind.'); 1484 1476 else: 1485 reporter.log('actionCleanupAfter: Python COM still has %s objects and %s interfaces...' % ( cObjs, cIfs)); 1486 from win32com.client import DispatchBaseClass; # pylint: disable=import-error 1487 for oObj in gc.get_objects(): 1488 if isinstance(oObj, DispatchBaseClass): 1489 reporter.log('actionCleanupAfter: %s' % (oObj,)); 1490 oObj = None; 1477 reporter.log('_teardownVBoxApi: Python COM still has %s objects and %s interfaces...' % ( cObjs, cIfs)); 1478 1479 from win32com.client import DispatchBaseClass; # pylint: disable=import-error 1480 for oObj in gc.get_objects(): 1481 if isinstance(oObj, DispatchBaseClass): 1482 reporter.log('_teardownVBoxApi: %s' % (oObj,)); 1483 aoObjsLeftBehind.append(oObj); 1484 elif utils.getObjectTypeName(oObj) == 'VirtualBoxManager': 1485 reporter.log('_teardownVBoxApi: %s' % (oObj,)); 1486 cVBoxMgrs += 1; 1487 aoObjsLeftBehind.append(oObj); 1488 oObj = None; 1491 1489 except: 1492 1490 reporter.logXcpt(); 1491 1492 # If not being used, we can safely uninitialize COM. 1493 if cIfs == 0 and cObjs == 0 and cVBoxMgrs == 0 and len(aoObjsLeftBehind) == 0: 1494 reporter.log('_teardownVBoxApi: Calling CoUninitialize...'); 1495 try: pythoncom.CoUninitialize(); # pylint: disable=no-member 1496 except: reporter.logXcpt(); 1497 else: 1498 reporter.log('_teardownVBoxApi: Returned from CoUninitialize.'); 1493 1499 else: 1494 1500 try: 1495 from xpcom import _xpcom as _xpcom; # pylint: disable=import-error1501 from xpcom import _xpcom as _xpcom; # pylint: disable=import-error 1496 1502 hrc = _xpcom.NS_ShutdownXPCOM(); 1497 cIfs = _xpcom._GetInterfaceCount(); # pylint: disable=W0212 1498 cObjs = _xpcom._GetGatewayCount(); # pylint: disable=W0212 1503 cIfs = _xpcom._GetInterfaceCount(); # pylint: disable=W0212 1504 cObjs = _xpcom._GetGatewayCount(); # pylint: disable=W0212 1505 1499 1506 if cObjs == 0 and cIfs == 0: 1500 reporter.log(' actionCleanupAfter: NS_ShutdownXPCOM -> %s, nothing left behind.' % (hrc, ));1507 reporter.log('_teardownVBoxApi: NS_ShutdownXPCOM -> %s, nothing left behind.' % (hrc, )); 1501 1508 else: 1502 reporter.log(' actionCleanupAfter: NS_ShutdownXPCOM -> %s, leaving %s objects and %s interfaces behind...' \1509 reporter.log('_teardownVBoxApi: NS_ShutdownXPCOM -> %s, leaving %s objects and %s interfaces behind...' 1503 1510 % (hrc, cObjs, cIfs)); 1504 1511 if hasattr(_xpcom, '_DumpInterfaces'): 1505 try: 1506 _xpcom._DumpInterfaces(); # pylint: disable=W0212 1507 except: 1508 reporter.logXcpt('actionCleanupAfter: _DumpInterfaces failed'); 1512 try: _xpcom._DumpInterfaces(); # pylint: disable=W0212 1513 except: reporter.logXcpt('_teardownVBoxApi: _DumpInterfaces failed'); 1514 1515 from xpcom.client import Component; # pylint: disable=import-error 1516 for oObj in gc.get_objects(): 1517 if isinstance(oObj, Component): 1518 reporter.log('_teardownVBoxApi: %s' % (oObj,)); 1519 aoObjsLeftBehind.append(oObj); 1520 if utils.getObjectTypeName(oObj) == 'VirtualBoxManager': 1521 reporter.log('_teardownVBoxApi: %s' % (oObj,)); 1522 cVBoxMgrs += 1; 1523 aoObjsLeftBehind.append(oObj); 1524 oObj = None; 1525 1509 1526 except: 1510 1527 reporter.logXcpt(); 1511 1528 self.checkProcessHeap(); ## TEMPORARY 1512 1529 1530 # Try get the referrers to (XP)COM interfaces and objects that was left behind. 1531 for iObj in range(len(aoObjsLeftBehind)): # pylint: disable=consider-using-enumerate 1532 try: 1533 aoReferrers = gc.get_referrers(aoObjsLeftBehind[iObj]); 1534 reporter.log('_teardownVBoxApi: Found %u referrers to %s:' % (len(aoReferrers), aoObjsLeftBehind[iObj],)); 1535 for oReferrer in aoReferrers: 1536 oMyFrame = sys._getframe(0); # pylint: disable=protected-access 1537 if oReferrer is oMyFrame: 1538 reporter.log('_teardownVBoxApi: - frame of this function'); 1539 elif oReferrer is aoObjsLeftBehind: 1540 reporter.log('_teardownVBoxApi: - aoObjsLeftBehind'); 1541 else: 1542 fPrinted = False; 1543 if isinstance(oReferrer, dict) or isinstance(oReferrer, list) or isinstance(oReferrer, tuple): 1544 try: 1545 aoSubReferreres = gc.get_referrers(oReferrer); 1546 for oSubRef in aoSubReferreres: 1547 if not isinstance(oSubRef, list) \ 1548 and not isinstance(oSubRef, dict) \ 1549 and oSubRef is not oMyFrame \ 1550 and oSubRef is not aoSubReferreres: 1551 reporter.log('_teardownVBoxApi: - %s :: %s:' 1552 % (utils.getObjectTypeName(oSubRef), utils.getObjectTypeName(oReferrer))); 1553 fPrinted = True; 1554 break; 1555 del aoSubReferreres; 1556 except: 1557 reporter.logXcpt('subref'); 1558 if not fPrinted: 1559 reporter.log('_teardownVBoxApi: - %s:' % (utils.getObjectTypeName(oReferrer),)); 1560 try: 1561 import pprint; 1562 for sLine in pprint.pformat(oReferrer, width = 130).split('\n'): 1563 reporter.log('_teardownVBoxApi: %s' % (sLine,)); 1564 except: 1565 reporter.log('_teardownVBoxApi: %s' % (oReferrer,)); 1566 except: 1567 reporter.logXcpt(); 1568 del aoObjsLeftBehind; 1569 1570 # Force garbage collection again, just for good measure. 1513 1571 try: 1514 1572 gc.collect(); 1515 time.sleep(0.5); # fudge factor y1573 time.sleep(0.5); # fudge factor 1516 1574 except: 1517 1575 reporter.logXcpt();
Note:
See TracChangeset
for help on using the changeset viewer.