PrayagS / polybar-spotify

:musical_note: Spotify status and controls module for Polybar with text scrolling
MIT License
581 stars 38 forks source link

Random polybar-msg error #5

Closed KivalM closed 3 years ago

KivalM commented 3 years ago

The script will randomly give an error saying "polybar-msg: No process with pid ######" where the "######" will be the correct pid of the bar.

For example 2020-10-09_152548-273x21_scrot

but 2020-10-09_152855-570x34_scrot

Reloading polybar fixes the problem temporarily. If music is playing, skipping to the next song or previous song fixes it temporarily

There is nothing in particular that seems to be causing it. This only happens maybe 2-3 times in an hour.

PrayagS commented 3 years ago

Do you use some kind of launch script to launch polybar? Can you please share details on how you launch the bars?

KivalM commented 3 years ago

Yes i do this is the script that i have to kill and relaunch polybar

#!/usr/bin/env sh

# Terminate already running bar instances
killall -q polybar

# Wait until the processes have been shut down
while pgrep -u $UID -x polybar >/dev/null; do sleep 1; done

# Launch bar1 and bar2
polybar -c ~/.config/polybar/config-1 bottommain &
polybar -c ~/.config/polybar/config-1 topmain &
PrayagS commented 3 years ago

Great! Can you add one line to kill zscroll everytime? So killall zscroll right below killall -q polybar. Even though I get this error very rarely (particularly when something like pywal restarts the bar to update the colors but that too not everytime), it is not often as you stated.

My first hunch when I saw this error was that the zscroll instance is still running while the bar is killed and hence, I added that line in the launch script. Let me know if you still see this error as often as you said. We might be able to work out a permanent solution.

KivalM commented 3 years ago

A possible solution i was thinking of could be to redirect stdout and stderr of the polybar-msg command to /dev/null so instead of polybar-msg -p "$(pgrep -f "polybar -c /home/ki/.config/polybar/config-1 bottommain")" hook next 1 >/dev/null I can do polybar-msg -p "$(pgrep -f "polybar -c /home/ki/.config/polybar/config-1 bottommain")" hook next 1 &>/dev/null My bash skills are not great though so i may be wrong

I will try your solution for now, but if the error persists I will try this Thanks

PrayagS commented 3 years ago

Rightly spotted! Redirecting stderr to null would suppress the error output and allow the playerctl output to be shown. You can do that by replacing that line with below:

polybar-msg -p "$(pgrep -f "polybar -c /home/ki/.config/polybar/config-1 bottommain")" hook next 1 1>/dev/null 2>&1

Here 1>/dev/null redirects stdout to null since 1 is the file descriptor for stdout. 2>&1 redirects stderr to whatever stdout which was previously redirected to null.

I suggest you make the change and if it doesn't give you the same error as often as you said, feel free to open a PR. I'd be happy to merge it.

stale[bot] commented 3 years ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

KivalM commented 3 years ago

I have created a PR for the proposed fix. Please feel free to take a look at it