nzbToMedia icon indicating copy to clipboard operation
nzbToMedia copied to clipboard

Questions: Python 7 End of Life and Delete Files

Open ulrick65 opened this issue 4 years ago • 12 comments

Not a bug report, but I wasn't sure where else to ask a question for this.

First off, awesome thing you have done here...really a top notch piece of work and I use it without issue on a daily basis. Well done.

Couple questions:

I use nzbget and the current version of nzbToMedia.

I am getting the log entry that "2.7 is nearing the end of life, upgrade to more recent version..."

I just upgraded my server and brand new install of Ubuntu 18.04.03 and it has Python 3.6.8 installed on it. I am not sure if the message is to be ignored or if for some reason, the script can't find Python3 or if there is something I need to do before the drop dead date to get it to use Python3?

Also, I have noticed for a long time that the script deletes a WHOLE BUNCH of files everytime it runs...which I assume it is creating at run time as well. I am curious what this is all about. Here's a section of the log I am talking about:

Thanks.

O Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing core/github_api.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing core/forks.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing core/extractor/init.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing core/databases.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing core/configuration.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing core/auto_process/tv.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing core/auto_process/music.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing core/auto_process/movies.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing core/auto_process/games.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing core/auto_process/common.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing core/auto_process/comics.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing core/auto_process/books.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing core/auto_process/init.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing core/init.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Removing cleanup.pyc
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: -- Cleaning bytecode --
INFO Wed Oct 23 2019 19:26:03 nzbToSickBeard: Changing to directory: /opt/nzbget/scripts/nzbToMedia

ulrick65 avatar Oct 30 '19 00:10 ulrick65

The script will call python from the system path... well more accurately it calls /usr/bin/env python for whichever user is running NZBGet.

So, if you have both python2 and python3, you would need to ensure that python is a symlink to python3 (or direct to python3.6 etc)

If that would cause issues for other applications, you can use NZBGet's shell override. NZBGet, Settings, Extension Scripts, Shell Override .py=/usr/bin/python3 use the full path to the appropriate python3 command. This will cause all .py scripts, called by NZBGet, to be executed with this version of python.

For the deleting files, this was introduced with a major restructure of the code... lingering .pyc files (compiled on each run of the code) were causing the update to fail, or otherwise breaking the script.

So this cleanup was introduced to ensure upgrades run smoothly... We do need to review this to see if this is still necessary, but the constant delete is relatively low resource usage, quick, and much better than the constant fuss of trying to fix a broken setup that failed to update.

clinton-hall avatar Oct 30 '19 08:10 clinton-hall

Is there a way to disable those messages from reporting then? It's not needed in my opinion to show those messages every time.

BlackDex avatar Oct 30 '19 09:10 BlackDex

Also, if this really breaks stuff. maybe putting the following in the source would be a good option.

import sys

sys.dont_write_bytecode = True

That would prevent the bytecode from being written at all

BlackDex avatar Oct 30 '19 09:10 BlackDex

Thanks for the feedback. I am curious why, if it requires Python3, it wouldn't use: /usr/bin/env python3 isn't that what it should do? I thought that #!/usr/bin/env python was only used when the script is both python2 and python3 compliant these days?

Thanks.

ulrick65 avatar Oct 30 '19 21:10 ulrick65

Fair point. The script is Python2 compliamt (and only recently made python3 compatible) but as per the message Python itself will be depreciating Python 2 soon.

Changing the hash-bang is interesting. While most *nix systens should work with python3, there are numerous busybox, NAS, and other embedded devices where this causes issues.

I'll try and look at this and see what I can do.

clinton-hall avatar Oct 30 '19 22:10 clinton-hall

@BlackDex Looks like a good solution. Can you test this to see of it does stop the reporting? If so, send a PR to nightly and I'll merge it.

clinton-hall avatar Oct 30 '19 22:10 clinton-hall

Good point on your response as well...I was thinking of it more of a script was needing python3 but like you said, it's really python2 going away...it is going to be interesting to see where it all goes as a standard...right now, the standard is python points to python2, but once gone (yea right!) then what?

Probably not worth a whole bunch of time right now...it was more a question then a request I guess. Maybe going forward it defaults to python3 and anything else requires a setting in config or something. You are way smarter than me on this stuff, I have complete confidence you will figure out the best way! I dabble in it...but I can not imagine making something like this that works on so many different platforms...astounding to me.

Thanks again for everything...great work.

ulrick65 avatar Oct 30 '19 23:10 ulrick65

@clinton-hall I was wondering if you had a chance to take a look at this yet? I am running into issues now using scripts in nzbget because if I force it to use Python 3 then a couple of my Python 2 scripts don't work...and vice verse. If the shebang was set up to point to Python3 here, then it would solve the problem...as the other scripts work fine without setting the shell override in nzbget as they specify Python3 directly in the shebang (#!/usr/bin/env python3).

Hoping you could do the same in nzbToMedia?

Thanks.

ulrick65 avatar Feb 23 '20 19:02 ulrick65

What I have done for now is continue allowing the script to run in python2. I am still concerned with changing the shebang as some systems may not have correct linking of python3. I will review this if/when new features cannot be practically supported in python2.

clinton-hall avatar Feb 24 '20 05:02 clinton-hall

I thought it required Python 3 to run? I did not realize it would run in 2.7 still?

ulrick65 avatar Feb 24 '20 12:02 ulrick65

I reverted to keep 2.7 (with a logged warning) due to this issue.

clinton-hall avatar Feb 24 '20 18:02 clinton-hall

Ahhh...perfect! Thanks for that. It makes my life a little better!

ulrick65 avatar Feb 25 '20 02:02 ulrick65