LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-08-2006, 05:32 PM   #1
_UnPrEdictAbLe_
Member
 
Registered: Aug 2004
Location: Hyderabad, India
Distribution: Fedora Core 4
Posts: 183

Rep: Reputation: 30
Unhappy Python Threads isAlive and start problem


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 ?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python problem - compiled from source - python -V still showing old version txm123 Linux - Newbie 1 02-15-2006 11:05 AM
Python threads Vookimedlo Programming 2 02-04-2006 08:42 PM
Java threads listed using kill -3 does not contain all threads found using ps -auxww coneheed Programming 2 11-14-2005 08:57 AM
how to start IDLE (Python) ilectrcbob Programming 10 06-18-2004 09:24 AM
Learning Python... where do i start?? Claus Programming 2 09-02-2003 06:42 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration