You are not logged in.

#1 2010-06-27 20:23:06

Foucault
Member
From: Athens, Greece
Registered: 2010-04-06
Posts: 214

Simple Awesome vicious widget problem

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

#2 2010-07-02 07:54:30

cantabile
Member
Registered: 2010-06-29
Posts: 37

Re: Simple Awesome vicious widget problem

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

#3 2010-07-04 15:45:22

gryf
Member
Registered: 2010-07-04
Posts: 1

Re: Simple Awesome vicious widget problem

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

#4 2011-01-02 00:53:12

pit
Member
From: Wrocław, Poland
Registered: 2010-10-11
Posts: 19
Website

Re: Simple Awesome vicious widget problem

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

#5 2011-01-02 04:02:06

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 835
Website

Re: Simple Awesome vicious widget problem

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

#6 2011-01-02 11:03:06

pit
Member
From: Wrocław, Poland
Registered: 2010-10-11
Posts: 19
Website

Re: Simple Awesome vicious widget problem

anrxc wrote:

I don't know why nvclock is blocking.

I've used nvidia-settings -t -q GPUCoreTemp, same effect.

anrxc wrote:

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

#7 2011-01-04 06:56:47

anrxc
Member
From: Croatia
Registered: 2008-03-22
Posts: 835
Website

Re: Simple Awesome vicious widget problem

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

Board footer

Powered by FluxBB