[pypy-dev] a bug of pypy:don't auto close the file handler.
聂宝鹏
niebaopeng at gmail.com
Wed Jan 11 06:35:20 CET 2012
description:
pypy don't close file opened in a function.the the program exit after
run a while because it open too
many files which exceed the limited of system.
the code is :
#!/usr/bin/env python
import os,time,signal
last = {}
now = {}
def stack(s,f):
global now,last
last = now
now = {}
lines=open("/proc/net/dev","rt").readlines()
#f=open("/proc/net/dev")
#lines=f.readlines()
#f.close()
ls=lines[2:] #del the header line
for m in range(0,len(ls)):
l=ls[m] # l = per line
name,l=l.split(':') # name = dev ,l = other;
l=l.split() # l = other.split items.
bytes_in = l[0]
bytes_out = l[8]
packets_in = l[1]
packets_out = l[9]
now[name]={}
now[name]['bytes_in']=bytes_in
now[name]['bytes_out']=bytes_out
now[name]['packets_in']=packets_in
now[name]['packets_out']=packets_out
if last:
print '-'*80
for name in now.iterkeys():
print "dev:
%s\tbytes:\trx:%.2fMb/s\ttx:%.2fMb/s\tpackets\trx:%s\ttx:%s" %
(name, int ( int(now[name]['bytes_in']) -
int(last[name]['bytes_in'])
)/1024.0/1024.0*8.0,int(int(now[name]['bytes_out'])-int(last[name]['bytes_out']))/1024.0/1024.0*8.0
,
int
( int(now[name]['packets_in']) - int(last[name]['packets_in'])
),int(int(now[name]['packets_out'])-int(last[name]['packets_out'])) )
print '-'*80
if __name__=='__main__':
signal.signal(signal.SIGALRM,stack)
signal.setitimer(signal.ITIMER_REAL,0.01,1.0)
while 1 :
signal.pause()
More information about the pypy-dev
mailing list