discord-rich-presence-plex icon indicating copy to clipboard operation
discord-rich-presence-plex copied to clipboard

[Question] Issue running in background

Open hotsno opened this issue 2 years ago • 7 comments

Running this script in the background isn't working for me both on macOS and Windows.

On macOS (and Linux) you're able to run commands in the background with & and then detach them from the terminal instance with disown. So the command I used is python3 main.py & disown. After doing this I get 1 line of output ([21-05-2022 08:43:26 PM] [INFO] Discord Rich Presence for Plex - v2.2.2) and then nothing else. When I play something in Plex, the RPC doesn't show up, so I'm guessing the script either isn't running or is failing. I do see the main.py process in the output of ps -ax | grep Python, however I'm not sure what I can conclude from this this. Trying this same command ( & disown) with a simple test Python script that just prints something every 2 seconds, output is generated every 2 seconds until I kill the process.

On Windows, I did as this issue comment suggested, but it also isn't seeming to work. Specifically, I tried both pythonw main.py and then I tried renaming the file extension of main.py to .pyw, as I was told to in some article I read, so pythonw main.pyw and neither of these worked. I made sure pythonw.exe is in my path variable, and also just tried replacing pythonw with the path of the .exe.

Has anyone else gotten it to work? Is there something I'm doing wrong? Any other suggestions for making the use of this script more convenient are also welcome.

hotsno avatar May 22 '22 03:05 hotsno

I have just committed a fix. Update your version of the script and let me know if the issue is fixed. If not, set writeToFile under logging in the config.json file to true, run the program, and check the output written to the console.log file.

phin05 avatar May 22 '22 04:05 phin05

Thanks for the quick fix and response! pythonw main.py works on Windows now.

I tried on macOS and it's still doing the same thing. I turned on logging to file and only this line shows up: [21-05-2022 10:30:29 PM] [INFO] Discord Rich Presence for Plex - v2.2.3

hotsno avatar May 22 '22 05:05 hotsno

I've made a couple changes to try to debug it. Update your copy of the script again and see if anything more gets logged.

phin05 avatar May 22 '22 17:05 phin05

Now I get 2 lines of output:

[22-05-2022 10:47:49 AM] [INFO] Discord Rich Presence for Plex - v2.2.4
[22-05-2022 10:47:49 AM] [INFO] [laptop/CD933] Signing into Plex

And the RPC doesn't seem to be working (when using & disown).

hotsno avatar May 22 '22 17:05 hotsno

It appears to be freezing on this line after the "Signing into Plex" message:

self.account = MyPlexAccount(token = self.token)

I'm not sure what the issue is since MyPlexAccount is imported from the PlexAPI module which is out of my control. I don't see any reason for it to act differently while the script is running in the background. I'm on Windows so I'm unable to test this on macOS.

phin05 avatar May 22 '22 18:05 phin05

personally in Windows I use a scheduled task :

in scheduler when starting the computer : start.cmd :

echo off c: cd C:\discord-rich-presence-plex-master start plex_rich_presence-noconsole.vbs exit

plex_rich_presence-noconsole.vbs :

strCommand = "cmd /c python main.py"

For Each Arg In WScript.Arguments strCommand = strCommand & " """ & replace(Arg, """", """""""""") & """" Next

CreateObject("Wscript.Shell").Run strCommand, 0, false

== cordially

GhislainSamy avatar Jul 10 '22 01:07 GhislainSamy

When using ctrl+z to suspend the script, then using bg, the script does not start up again and update the rich presence in Discord. It just continues to use the last updated information. (e.g. Shows old song even after new song is played)

Running fg immediately updates the script. So something is messing with the backgrounding of this on macOS.

GreenglassT avatar Jul 10 '22 07:07 GreenglassT

On Windows I run it in the background by renaming main.py to main.pyw. Then just make a shortcut out of it and place this shortcut in your Startup folder. You can do this by opening Run with Win+R and then type shell:startup. Works on every version of Windows for me with a basic Python install.

zeroquinc avatar Jun 16 '23 21:06 zeroquinc

On Windows I run it in the background by renaming main.py to main.pyw. Then just make a shortcut out of it and place this shortcut in your Startup folder. You can do this by opening Run with Win+R and then type shell:startup. Works on every version of Windows for me with a basic Python install.

I tried using your method but this shows up on my console.txt

[29-10-2023 11:16:19 PM] [INFO] Discord Rich Presence for Plex - v2.3.4 [29-10-2023 11:16:19 PM] [INFO] [myServer/69AA2] Signing into Plex [29-10-2023 11:16:19 PM] [ERROR] An unexpected error occured Traceback (most recent call last): File "C:\discord-rich-presence-plex\main.pyw", line 65, in if sys.stdin.isatty(): ^^^^^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'isatty'

TsunaSetsu avatar Oct 30 '23 03:10 TsunaSetsu

@TsunaSetsu That issue should be fixed now. Try the new version (2.3.5).

phin05 avatar Oct 30 '23 04:10 phin05

Actually on my Windows 11 :

Scheduled Task : Start a program : "C:\discord-rich-presence-plex\start_plex_rich_presence.cmd"

start_plex_rich_presence.cmd :

cd C:\discord-rich-presence-plex
start pythonw main.py

Test : OK

GhislainSamy avatar Dec 25 '23 15:12 GhislainSamy

I'm closing this as stale.

Feel free to post a comment if you are still facing this issue, after testing again using the latest version.

phin05 avatar Feb 10 '24 18:02 phin05

It's still happening on macOS, I actually just started using this project again a few days ago :) I updated the post with a workaround I'm using.

hotsno avatar Feb 11 '24 00:02 hotsno

You tried v2.6.0? It still freezes after the "Signing into Plex" line?

phin05 avatar Feb 11 '24 05:02 phin05

So I decided to ask ChatGPT and I think it found the issue lol: https://chat.openai.com/share/0ab59919-d751-41f4-adad-bda038a7f855

The issue no longer happens with python3 main.py </dev/null & disown

As you said before, it seems to be out of this project's control and is an issue in the Python Plex API. Here's a starting point for where to look, but I'm satisfied with the solution above.

hotsno avatar Feb 11 '24 05:02 hotsno