[Tutor] close failed in file object destructor:
Navneet
rocklearnpython at gmail.com
Tue Oct 18 19:59:50 CEST 2011
Hi,
I am trying to search a list for prime numbers but it's throwing me an
error at line no.25.
I am not able to figure what exactly is the prob
ne help ??? Error is this:
$ python "prime1 - Copy.py"
Unhandled exception in thread started by
Traceback (most recent call last):
File "prime1 - Copy.py", line 25, in findPrime
close failed in file object destructor:
Error in sys.excepthook:
program is below: Numberlist is number range from 1..1000
import sys
import threading
import thread
import time
class FindPno():
c = []
f = open("A;\Numberlist.txt")
for i in f:
c.append(i)
f.close()
##print len(c)
##Thread should start here
def __init__(self):
thread.start_new_thread(self.findPrime,(1,))
def findPrime(self,tid):
global tlock
## print "I am here"
tlock = thread.allocate_lock()
## print "I am here"
tlock.acquire()
## print "I am here"
for i1 in range(len(c)): ##this is the 25th line
for i2 in range(2,int(c[i1])):
if int(c[i1]) == 1:
print "I am here"
tlock.release()
break
if int(c[i1]) == 2:
print c
print "I am here"
tlock.release()
break
rem = int(c[i1])%i2
if rem == 0:
print "I am here"
tlock.release()
break
if i2 == int(c[i1])-1:
print int(c[i1]), "This is the Thread",tid
print "I am here"
tlock.release()
tlock.release()
if __name__ == '__main__':
a = FindPno()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20111018/88c38ccf/attachment-0001.html>
More information about the Tutor
mailing list