Win32 exception occurred releasing IUnknown at 0xe3e0ebc8
I found a similiar issue reported https://github.com/SethMichaelLarson/virtualbox-python/issues/52 but I wasn't able to reproduce that issue. Instead I found the error when running vbox in a thread.
ENVIRONMENT
- Operating System: Windows 7, Windows 10
- Python version: 3.6.2
- VirtualBox version: 5.2.12 r122591
- VirtualBox SDK version: 5.2.12-122591
- Location where VirtualBox SDK is installed: ...\Python3\Lib\site-packages
- pyvbox version: 1.3.2
- [ x] Happens in latest
masterbranch?
SUMMARY
During the second iteration of the while loop, where the th variable gets reassigned, the python app crashes and produces a Win32 exception. The crash seems to stem from release and reassignment of the self.session and self.vbox variables.
STEPS TO REPRODUCE
import virtualbox
import threading
import time
class ThreadExecutor(threading.Thread):
def __init__(self):
self.vbox = None
self.session = None
self.vm = None
super().__init__()
def run(self):
self.vbox = virtualbox.VirtualBox()
self.session = virtualbox.Session()
self.vm = self.vbox.find_machine("Ubuntu")
self.vm.launch_vm_process(self.session, 'gui', '')
time.sleep(30)
if int(self.session.state) == 1:
print('Boot failed!')
return
else:
print('Powering down')
self.session.console.power_down()
print('Operation completed')
return
if __name__ == '__main__':
while True:
print('Input')
if input():
th = ThreadExecutor()
th.start()
print('Thread started')
time.sleep(5)
while th.isAlive():
print('App running')
time.sleep(5)
print('Execution finished')
EXPECTED RESULTS
New vbox and sessions should be able to start after powering down the first session.
ACTUAL RESULTS
Win32 exception occurred releasing IUnknown at 0x035e40b8
Win32 exception occurred releasing IUnknown at 0x04babcb0
I think I've seen this before too, I was unable to figure out why. The only thing I can think of is objects being de-allocated and threading not playing nice together.
Yeah, there seems to be some issues with threading and virtualbox. I get the following exception when trying to run PyCharm debugger or Flask from console on the same code.
Traceback (most recent call last):
File "C:\Program Files\Python36\lib\site-packages\vboxapi\__init__.py", line 449, in __init__
None)
pywintypes.com_error: (-2147221008, 'CoInitialize has not been called.', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/JerryL/Documents/Aptiv/Python/VASP/grand_compile_auto/dev/issue_oXctp_not_defined.py", line 20, in run
self.vbox = virtualbox.VirtualBox()
File "C:\Program Files\Python36\lib\site-packages\virtualbox\library_ext\vbox.py", line 22, in __init__
manager = virtualbox.Manager()
File "C:\Program Files\Python36\lib\site-packages\virtualbox\__init__.py", line 143, in __init__
self.manager = vboxapi.VirtualBoxManager(mtype, mparams)
File "C:\Program Files\Python36\lib\site-packages\vboxapi\__init__.py", line 991, in __init__
self.platform = PlatformMSCOM(dPlatformParams)
File "C:\Program Files\Python36\lib\site-packages\vboxapi\__init__.py", line 455, in __init__
print("Warning: CoInitializeSecurity failed: ", oXctp);
NameError: name 'oXctp' is not defined