I made a function called listProcesses
which calls the following Vix commands, in this order:
- VixHost_Connect
- VixHost_OpenVM
- VixVM_LoginInGuest
- VixVM_ListProcessesInGuest
- VixVM_LogoutFromGuest
- VixHost_Disconnect
Notice that I do not call VixVM_PowerOn
because I power on the virtual machine by hand.
The function listProcesses()
is written in C but I export it as a .pyd
file to be used with Python.
In the Python interpreter I run the following code:
from myModule import listProcesses
for i in xrange(1000):
print listProcesses()
The function listProcesses()
gives me the exprected output (a list of strings representing the processes names running inside the virtual machine) for the first ~30 iterations of the for
loop, but after that it starts printing an empty list.
I used the debugger in Visual Studio 2012 to investigate and it looks like after ~30 iteration of the for
loop, the function VixVM_LoginInGuest()
returns error 3006
. From the Vix documentation, that error means "The virtual machine needs to be powered on.".
I have checked and the virtual machine is powered on and responding and VmwareTools are still running inside the virtual machine.
I'd like to add that I realease all the handles as recommended by the documentation. Also, if it's any help, if I pause the execution of the python script after I start getting the error and I restart the virtual machine, the script starts printing the exprected output for another ~30 (depending on the host I've ran the script in, it might be as much as 80) times, and then it starts printing an empty list again.
I would some insight on why this problem might occur.
EDIT:
After I investigated further, I noticed that the function VixHost_OpenVM
creates a TCP connection to the virtual machine, and the connection is never closed. When the number of connection reaches a certain number, the OS probably forbids any new connection comming from my script. Is there a way to close the unused connection without closing the script?
I have found an answer to my question, and since it looks like nobody is going to answer it I'm gonna post the answer myself for people that might run into this problem in the future.
The problem was that I called
VixHost_Connect
every time I ran the function, and because of that the functionVixHost_OpenVM
would create a new (TCP) connection to the virtual machine every time. After a few calls, I'd reach the limit of TCP connection imposed by the operating system, and further calls toVixHost_OpenVM
would fail.The solution is to call the function
VixHost_Connect
in theinitmodule()
function, and store the handle as a global variable that the other methods can use. After I've done this, mylistProcesses()
function looks like this:Because I use the same handle to Vmware every time I run
listProcesses()
, a TCP connection to the virtual machine is created only if one does not already exist, and I can call the function as many times as I want.