[Python-ideas] threading : AttributeE???rror: 'NoneType' object has no attribute 'start'

C. Titus Brown ctb at msu.edu
Mon Sep 12 05:00:12 CEST 2011


On Sun, Sep 11, 2011 at 07:54:28PM -0700, Sagar Neve wrote:
> 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'

[ ... ]

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

> 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"
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas

-- 
C. Titus Brown, ctb at msu.edu



More information about the Python-ideas mailing list