performance - python script keeps using 120% CPU -
i'm having issue websocket script. on time consumes more , more cpu. 1 remedy i've discovered clear associated logfile. resolves problem little while, cpu usuage builds 120% in little on day or so. (using top command on linux server)
the part of script file write looks bit odd me. here code:
f = open(file, 'a') f.write(line+"\n") os.fsync(f.fileno()) f.flush() f.close
i'm not python expert, starters, last 3 things rather same in opinion. python manual states http://docs.python.org/2/library/os.html#os.fsync f.flush , os.fsync should in reverse order...
can use:
f = open(file, 'a') f.write(line+"\n") f.close
and should not be: f.close()??
any ideas?
use open (and automatically close) files:
with open(filename, 'a') f: f.write(line+"\n")
Comments
Post a Comment