Detect VNC disconnect

Asked by Dillon

I am trying to detect when a VNC connection is stopped.

I have a script that runs an installer that requires the machine to be restarted during the installation. Currently, I have a wait function that waits for 5 minutes. Normally my machine starts up within 2 minutes but in the off chance that a VM I'm running needs something such as Windows Updates, it causes the restart to be longer, hence the 5 minute wait. What I'm looking to do is detect when the machine is turned off and then back on, rather than waiting for a hardcoded 5 minutes.

When the machine is turned off that I am connected to, I get a java exception that spams in the console. I can't catch because it isn't generated directly from the scripts code, rather from the VNC connection being halted.

Any insight around this topic would be greatly appreciated.

Question information

Language:
English Edit question
Status:
Expired
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Dillon (dillonm197) said :
#1

I do have a function that can be used to keep retrying to reconnect to VNC in the event that the server is still powered off, but this still requires a hard coded time to wait for the server to power off and power back on.

def restartVNC(reg, ip_, port_, password_, time):
 reg.stop()
 log("Reconnecting to VNC connection after {0} seconds.".format(time))
 wait_(time)
 while(True):
  try:
   reg = vncStart(ip = ip_, port = int(port_), password = password_, connectionTimeout = 10, timeout = 1000)
  except:
   pass
  if reg:
   log("VNC connection reestablished.")
   break
 return reg

Revision history for this message
TestMechanic (ndinev) said :
#2

It seems like you should retry let say every 20 seconds for up to 5 minutes. If connections is OK just break the wait loop.

Revision history for this message
Dillon (dillonm197) said :
#3

I've been doing something along those lines, but unfortunately this can sometimes cause an issue in the event the computer takes longer than said 20 seconds to log off and power off.

Essentially what I currently have working is:
- Power off machine
- Disconnect VNC
- Wait ~2 minutes (Computer should have powered off by now. If you reconnect too soon, the computer may power off while VNC is connected, resulting in an non-catchable exception, or maybe it's a signal?)
- Keep attempting to reconnect to VNC (Which means the machine is now powered on)

What I'm wanting:
- Detect when machine is powered off and catch VNC disconnect exception
- Keep attempting to reconnect to VNC (Which means the machine is now powered on)

All in all it's just an optimization I'm looking for. Not required, but would prevent errors in the futures since I'm running this nightly for each build of software.

Revision history for this message
Launchpad Janitor (janitor) said :
#4

This question was expired because it remained in the 'Open' state without activity for the last 15 days.