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

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -