You are not logged in.
I'm messing around a bit with Awesome and I'm trying to write a simple vicious widget to read the nvidia card temperature. See what I've done so far
-- {{{ Grab environment
local type = type
local tonumber = tonumber
local setmetatable = setmetatable
local string = { match = string.match, format = string.format, sub = string.sub, gsub = string.gsub }
local helpers = require("vicious.helpers")
local print = print
local io = {popen = io.popen }
local assert = assert
-- }}}
module("vicious.widgets.thermalnv")
function string:split(sep)
local sep, fields = sep or ":", {}
local pattern = string.format("([^%s]+)", sep)
self:gsub(pattern, function(c) fields[#fields+1] = c end)
return fields
end
local function worker(format,arg)
local command = "nvclock -i"
local f = io.popen('/usr/bin/nvclock --info | grep temp','r')
local s = f:read("*all")
f:close()
s = string.gsub(s, '^%s+', '')
s = string.gsub(s, '%s+$', '')
s = string.gsub(s, '[\n\r]+', ' ')
local res = string.split(out,': ')
return {string.sub(res[3],1,-2)}
end
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
So, the problem is that Awesome stops loading when it reaches io.popen('/usr/bin/nvclock --info | grep temp','r') and will not exit unless I "killall -9" it. The funny thing is that the very same script works fine as a standalone script. Also, it works fine if the command in popen does not contain anything else except for '/usr/bin/nvclock'. Any ideas?
Last edited by Foucault (2010-06-27 20:23:28)
Offline
It's pretty obvious that popen doesn't do pipes. On the other hand, you say it works fine as a standalone script... hmm.
Use f:read("*line") until you get to the line you want, then use lua's string functions to extract the temp.
Last edited by cantabile (2010-07-02 07:57:15)
Offline
Even using f:read("*line") will not help. I've bumped against the very same problem, and didn't found any reasonable solution for this.
Furthermore (what is really weird), killing nvclock from the console will unblock awesome, and then widget is working just fine.
Here is mine version of the thermal widget:
------------------------------------------------------
-- Dead simple temperature widget for Nvidia gfx cards
------------------------------------------------------
-- {{{ Grab environment
local type = type
local tonumber = tonumber
local setmetatable = setmetatable
local io = {popen = io.popen}
local os = {getenv = os.getenv}
-- }}}
-- Thermalnvidia: provides temperature for nvidia gfx cards
module("vicious.widgets.thermalnvidia")
-- {{{ Read temperature from nvclock utility
local function get_gpu_temp()
local gpu_temp = nil
if os.getenv('DISPLAY') then
local f = io.popen("nvclock -T 2>&1 | grep temper| sed -E 's/^.+\\: ([0-9]+)C$/\\1/'")
gpu_temp = f:read("*all")
f:close()
end
return gpu_temp
end
-- }}}
-- {{{ Thermal widget type
local function worker(format)
-- Get temperature from thermal zone
local res = get_gpu_temp()
if res then
return {tonumber(res)}
end
return {0}
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
Last edited by gryf (2010-07-05 19:27:26)
Offline
Right now I'm fighting with the same problem with io.popen - did anybody found some solution for this ridiculous error? I've went through Google - no luck. My brain is going to explode...
Offline
I don't know why nvclock is blocking. I'd try to run it from cron and write data to some /tmp/file. In awesome you don't need a widget or anything, just a 3 line function in rc.lua that will read the contents of the file. Register that function as the widget type.
You need to install an RTFM interface.
Offline
I don't know why nvclock is blocking.
I've used nvidia-settings -t -q GPUCoreTemp, same effect.
I'd try to run it from cron and write data to some /tmp/file.
Umm, cron doesn't seems like a best idea for temp measuring, IMO.
Offline
If something hangs it wouldn't be a big problem. But awesome has a huge problem there since it can be blocked. There was a person on #awesome the other day who blocked awesome with amixer - which everyone is using for their widgets. I have no explanation for this now.
You need to install an RTFM interface.
Offline