[Tutor] setting up a timer

Lloyd Kvam pythontutor@venix.com
Tue, 02 Jul 2002 14:27:50 -0400


I have some logic for starting and connecting to a MySQL database that I
believe could get stuck because of network problems or remote server
problems.  I'd like to have a timer to simply cancel the process if it is
not successful in a reasonable time frame.  My search didn't turn up any
examples, so I coded the following (my unix/C roots are showing).

Then I discovered that signal.alarm is NOT available in Windows.  Mark
Hammond's book (Python Programming on Win32) was no help.  Please point
me in the right direction.

def timeout( signo, frame):
	raise RuntimeError( "Timed out trying to connect to database server")

def startup( login_name, passwd, svc_host, datadir, dbname):
	signal.signal( signal.SIGALRM, timeout)
	signal.alarm( 20)	# allow twenty seconds to succeed
	while 1:
		if did_startup_successfully():
			break
	signal.alarm(0)		# cancel alarm		

-- 
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358

voice: 
603-443-6155
fax: 
801-459-9582