Hi,
I am very new to python. I wrote some code which goes like this...
Code:
class ListGenThread ( threading.Thread ):
def __init__ ( self, logfile ):
threading.Thread.__init__(self)
self.logfile = logfile
def run ( self ):
path = iYumServer_getAttr ("SERVERACTPATH") + iYumServer_getAttr ("UPDATELISTDIR")
cursor = iYumServer_connectdb()
result = iYumServer_executeQuery ( cursor, "select releasever, arch from platform" )
threadlist = []
for i in result:
newthread = ListGenRepo ( i[0], i[1], path )
threadlist.append (newthread)
newthread.start()
for i in threadlist:
print "Waiting...",
i.join()
print "done"
file(self.logfile,"a").write (time.ctime()+" : Generated list "+str(i.ver)+"-"+i.arch+"\n")
print "I am exiting"
listgen = ListGenThread (logfile)
downman = DownloadManager (logfile, 1)
createpseudo = CreatePseudo (logfile)
file (logfile, "w").write (time.ctime()+" : Initializing server ("+str(init_time)+")\n")
while 1:
meta_up_int = int (iYumServer_getAttr ("METAUPDATEINT"))
list_check_int = int (iYumServer_getAttr ("LISTCHECKINT"))
duration = get_time() - init_time
flag = 0
flag2 = 0
if duration % list_check_int < 10 and listgen.isAlive() == False:
file (logfile, "a").write (time.ctime()+" : Starting update lists ("+str(duration)+")\n")
listgen.start()
flag = 1
if duration % meta_up_int < 10 and not createpseudo.isAlive() :
file(logfile,"a").write (time.ctime()+" : Starting update meta ("+str(duration)+")\n")
createpseudo.start()
flag2 = 1
if not flag and not flag2 and duration % 100 == 0:
file(logfile,"a").write (time.ctime()+" : Idle ("+str(duration)+")\n")
time.sleep (1)
duration = get_time() - init_time
if duration % 100 == 0 or len(downman.threadlist)+downman.maxpacks<5:
downman.reinit (5)
time.sleep(1)
if not downman.isAlive():
file(logfile,"a").write (time.ctime()+" : Downloading files ("+str(duration)+")\n")
downman.start()
time.sleep (10)
All this is just a part of the code. So basically, the 'listgen' thread is started periodically. There are others threads too, like 'downman' and 'createpseudo' which run periodically.
Technically, listgen.isAlive() should give the execution status of the thread. I check whether is thread listgen isAlive(). If its not, I do listgen.start(). Even after this, its giving an error. I even gave prints in the thread, and it suggests that its exiting.
Here is a sample output :
Code:
Waiting... done
Waiting... done
Waiting... done
Waiting... done
Waiting... done
Waiting... done
Waiting... done
Waiting... done
Waiting... done
Waiting... done
Waiting... done
Waiting... done
I am exiting
Traceback (most recent call last):
File "./iyumservice", line 199, in ?
listgen.start()
File "/usr/lib/python2.4/threading.py", line 410, in start
assert not self.__started, "thread already started"
AssertionError: thread already started
Any ideas ?