Question

I made a function called listProcesses which calls the following Vix commands, in this order:

  1. VixHost_Connect
  2. VixHost_OpenVM
  3. VixVM_LoginInGuest
  4. VixVM_ListProcessesInGuest
  5. VixVM_LogoutFromGuest
  6. 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?

Was it helpful?

Solution

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 function VixHost_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 to VixHost_OpenVM would fail.

The solution is to call the function VixHost_Connect in the initmodule() function, and store the handle as a global variable that the other methods can use. After I've done this, my listProcesses() function looks like this:

  1. VixHost_OpenVM
  2. VixVM_LoginInGuest
  3. VixVM_ListProcessesInGuest
  4. VixVM_LogoutFromGuest

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top