threading : AttributeError: 'NoneType' object has no attribute 'start'

I am new to the python and I need a small script to be written using threads which reads the specific files present in a directory and does some selections of lines and then write those lines into different files. However the error I am getting is: AttributeError: 'NoneType' object has no attribute 'start' Here is the code. Can somebody please help me. This is very urgent. def getFiles(fname): fname=preprocessLogFileDir + "/" + fname print fname fin = open(fname, "r") line=fin.readline() print line .... # some extraction logic. fout = open("out-single-file/1xx_2xx_total", "w") fout.write(line) fout.close() files=os.listdir(preprocessLogFileDir) cnt=1; for fname in files: print fname if fnmatch.fnmatch(fname,'*.log'): #and os.path.isfile(fname): thr = "thr" + str(cnt) print thr thr=getFiles(fname) thr.start() thr.join cnt = cnt + 1 else: print "\npreprocessLogFileDir/fname is either a directory or does not end with 'log'." print "Probabally not a pre-process file. Ignoring the file.\n\n"

On Sun, Sep 11, 2011 at 07:54:28PM -0700, Sagar Neve wrote:
[ ... ] Hi Sagar, this isn't the right place to post questions about how to use Python -- this is python-ideas, a list for discussing future changes to the language. Please go to http://mail.python.org/mailman/listinfo/python-list with future requests for help.
Here is the code. Can somebody please help me. This is very urgent.
...and note that your urgency is not ours, since you're not paying us! That having been said, at least one source of your problems is that 'getFiles' doesn't return a value. It's kind of hard to figure out what you want it to do; 'thr.start()' followed by 'thr.join()' immediately isn't going to result in much threading, unless there's more going on here than meets the eye. You might want to use something like thr = threading.Thread(target=getFiles) instead. See http://docs.python.org/library/threading.html#thread-objects And please ask future questions elsewhere. thanks! cheers, --titus
-- C. Titus Brown, ctb@msu.edu

On Sun, Sep 11, 2011 at 22:54, Sagar Neve <nevesagar@gmail.com> wrote:
Here is the code. Can somebody please help me. This is very urgent.
First off, python-ideas is not the right place to ask for programming help--it's for suggesting changes to the Python language itself. You will have better results posting to a help site like stackoverflow.com. In your case, it looks like you want to create a thread, but "thr = getFiles(fname)" is not doing that--it's just calling a function. You probably want to change this to "thr = threading.Thread(target=getFiles, args=(fname,))" -- Tim Lesher <tlesher@gmail.com>

Sagar Neve, 12.09.2011 04:54:
As others have told you, there are better lists to ask this kind of question. Specifically the python-tutor mailing list is a dedicated and friendly place for new users to ask questions. http://mail.python.org/mailman/listinfo/tutor Stefan

On Sun, Sep 11, 2011 at 07:54:28PM -0700, Sagar Neve wrote:
[ ... ] Hi Sagar, this isn't the right place to post questions about how to use Python -- this is python-ideas, a list for discussing future changes to the language. Please go to http://mail.python.org/mailman/listinfo/python-list with future requests for help.
Here is the code. Can somebody please help me. This is very urgent.
...and note that your urgency is not ours, since you're not paying us! That having been said, at least one source of your problems is that 'getFiles' doesn't return a value. It's kind of hard to figure out what you want it to do; 'thr.start()' followed by 'thr.join()' immediately isn't going to result in much threading, unless there's more going on here than meets the eye. You might want to use something like thr = threading.Thread(target=getFiles) instead. See http://docs.python.org/library/threading.html#thread-objects And please ask future questions elsewhere. thanks! cheers, --titus
-- C. Titus Brown, ctb@msu.edu

On Sun, Sep 11, 2011 at 22:54, Sagar Neve <nevesagar@gmail.com> wrote:
Here is the code. Can somebody please help me. This is very urgent.
First off, python-ideas is not the right place to ask for programming help--it's for suggesting changes to the Python language itself. You will have better results posting to a help site like stackoverflow.com. In your case, it looks like you want to create a thread, but "thr = getFiles(fname)" is not doing that--it's just calling a function. You probably want to change this to "thr = threading.Thread(target=getFiles, args=(fname,))" -- Tim Lesher <tlesher@gmail.com>

Sagar Neve, 12.09.2011 04:54:
As others have told you, there are better lists to ask this kind of question. Specifically the python-tutor mailing list is a dedicated and friendly place for new users to ask questions. http://mail.python.org/mailman/listinfo/tutor Stefan
participants (4)
-
C. Titus Brown
-
Sagar Neve
-
Stefan Behnel
-
Tim Lesher