powerline / powerline

Powerline is a statusline plugin for vim, and provides statuslines and prompts for several other applications, including zsh, bash, tmux, IPython, Awesome and Qtile.
https://powerline.readthedocs.org/en/latest/
Other
14.36k stars 997 forks source link

Can't enable cpu_load_percent_module! #1700

Open mskrzetuski opened 7 years ago

mskrzetuski commented 7 years ago

I'm getting following error message.

2017-01-05 14:52:45,265:ERROR:shell:CPULoadPercentSegment:Exception while updating: 'CPULoadPercentSegment' object has no attribute 'update' Traceback (most recent call last): File "/usr/lib/python2.7/site-packages/powerline/lib/threaded.py", line 71, in set_update_value self.update_value = self.update(self.update_value) AttributeError: 'CPULoadPercentSegment' object has no attribute 'update'

My configuration looks as follows.

"segments": {
                "left": [
                        {
                                "function": "powerline.segments.shell.mode"
                        },
                        {
                                "function": "powerline.segments.common.net.hostname",
                                "priority": 10
                        },
                        {
                                "function": "powerline.segments.common.env.user",
                                "priority": 30
                        },
                        {
                                "function": "powerline.segments.common.env.virtualenv",
                                "priority": 50
                        },
                        {
                                "function": "powerline.segments.shell.cwd",
                                "priority": 10
                        },
                        {
                                "function": "powerline.segments.shell.jobnum",
                                "priority": 20
                        },
                        {
                                "function": "powerline.segments.common.sys.cpu_load_percent",
                                "args": {
                                        "interval": 1,
                                        "format": "u'{0:.0f}%'",
                                        "shutdown_event": "none",
                                        "update_first": "true"
                                }
                        }
                ]
ZyX-I commented 7 years ago

Arguments to the segment are invalid:

  1. shutdown_event argument must not be supplied. Dunno how it appeared in documentation at all, but even if you wanted to set it to None you should’ve used null.
  2. update_first set to true is default, no need to specify it. And it should be boolean, not string. true is boolean, "true" is string.
  3. format argument you supplied looks like default… but it is not. Default is "{0:.0}%", not "u'{0:.0f}%'". u'…' is Python unicode string and here is JSON with different quoting style.
  4. interval 1 is default, no need to specify it. Though this should not cause any harm.

Errors are mostly harmless, except for shutdown_event setting. It looks like you don’t need to supply args dictionary at all.

ZyX-I commented 7 years ago

Ah, and don’t use backtick for multiline code snippets. Use three backticks to start and end the snippet, each on its own line. E.g.

```JSON
"segments": {
    …
}
```

which results in

"segments": {
    …
}

(JSON after backticks is optional code language, used for highlighting.)

dscole commented 5 years ago

Ran into the same issue today and after looking at the code I realized that the real issue behind it is that I didn't have psutil properly installed. So the fix is

pip install psutil

Would have been nice to get a more informative error message :)

UPDATE: After a second look, it looks like there was a good intention to have a proper warning, but the fallback CPULoadPercentSegment class seems to be missing it's update function: https://github.com/powerline/powerline/blob/develop/powerline/segments/common/sys.py#L101