[Tutor] lockfiles and timestamps and nested if's!

D-Man dsh8290@rit.edu
Thu, 17 May 2001 16:10:21 -0400


On Thu, May 17, 2001 at 02:43:05PM -0700, kromag@nsacom.net wrote:
| I have managed to get myself into a dither here. The script for some reason 
| always writes a new lock file and updates the timestamp. Can someone clue me 
| in? My brain is full.
| 
| import glob
| import time
| import string
| import os
| import socket
| 
| now=time.time()
| mybox=socket.gethostname()+'.txt'
| whoa=glob.glob('\tmp\*')

Right here insert the line

print whoa

I bet it isn't what you think it is.

| if whoa==['\tmp\'+mybox]:
| 	lockfile=open('\tmp\'+mybox, 'r')
| 	timestamp=lockfile.readline()
| 	print timestamp
| 	lockfile.close()
| 	if timestamp > time.time()-10:
| 		print 'old lockfile ok',
| 	else:
| 		os.remove('\tmp\'+mybox)
| 		
| else:
| 	lockfile=open('\tmp\'+mybox, 'w')
| 	lockfile.write(`now`)
| 	print 'new lockfile'
| 	print 'and contiue with the rest of this balderdash!

| whoa=glob.glob('\tmp\*')
| if whoa==['\tmp\'+mybox]:

I notice you used backslashes here (\).  I think you meant to use
forward slashes (/).  The \t gets expanded to a tab character.

-D