getting error from open
Posted: Thu Dec 22, 2011 12:15 pm
I'm using i3 with dzen bar and I'm using newlisp to build me a pretty customized bar.
I have this code to check for cpuload:
Script runs ok for a while, with a (sleep 1000) between calls, and then spits this:
I added a (println procStat) and found script stopped when procStat would take value 1024, so it sounded like I was hitting an OS limit there. So I wrote a new script to test that:
With this script the opening handle remains constant (at value 4 in my test).
The difference with the "real" script is that I have a status script that loads a cpuload module which contains read-proc-stat function definition.
I wonder why same function gets a constant handle when I call it one way and an incremented one (in steps of 4) when I call it the other way.
I modified read-proc-stat like this:
Which fixed the issue. But now I wonder: since I'm not closing the file ever, does newlisp close opened file handles when script finishes? What if it finishes with ctrl-c or what if it explodes on some other part? Does it do a proper cleaning?
I have this code to check for cpuload:
Code: Select all
(define (read-proc-stat)
(setq procStat (open "/proc/stat" "read"))
(do-while (regex {cpu\d?} (read-line procStat))
(parse-stat-line (current-line)))
(close procStat))
Code: Select all
ERR: value expected in function read-line : procStat
called from user defined function read-proc-stat
called from user defined function draw-cpu-load
Code: Select all
(define (read-proc-stat)
(setq proc-stat (open "/proc/stat" "read"))
(println "open handle: " proc-stat)
(do-while (regex {cpu\d?} (read-line proc-stat))
(println (current-line)))
(close proc-stat))
(while true
(read-proc-stat)
(sleep 1000))
The difference with the "real" script is that I have a status script that loads a cpuload module which contains read-proc-stat function definition.
I wonder why same function gets a constant handle when I call it one way and an incremented one (in steps of 4) when I call it the other way.
I modified read-proc-stat like this:
Code: Select all
(define (read-proc-stat:read-proc-stat)
(if (nil? read-proc-stat:procStat)
(setq read-proc-stat:procStat (open "/proc/stat" "read")))
(do-while (regex {cpu\d?} (read-line read-proc-stat:procStat))
(parse-stat-line (current-line)))
(seek read-proc-stat:procStat 0))