 |
 |
 |
 |
| Using Fedora General support for current versions. Ask questions about Fedora and it's software that do not belong in any other forum. |

18th March 2012, 01:00 PM
|
|
Registered User
|
|
Join Date: Feb 2012
Location: Canterbury, Kent, UK
Posts: 5

|
|
|
trouble with python script and cron
Hello all,
I've searched extensively in this forum and found no mention of a similar problem, so here goes: I have written a little Python script to randomly rotate my wallpaper (since GNOME 3 removed that ability). My first approach to it was quite silly, since I had put it running in a loop and of course that required a lot of CPU time.
Then I started looking at cron. I set up a simple call to the script (which is in my user home) every 2 minutes. Trouble is, I can see that crond effectively called it (I've been watching /var/log/cron for some time) but does not run it. (and yes, the script does run when I call it manually!  )
I've tried putting it in the system's crontab (/etc/crontab) and the user's one, I've also tried to make root run the script instead of me (in case my user account is not authorised to run cronjobs...), and I even tried to disable SELinux to see if that help (it didn't).
Can you please give me a hand with this? Oh, and my machine is running the 64-bit version of Fedora 16. (no rawhide, just standard updates, I want to keep it as stable as possible...)
Best regards,
Manuel Marques
|

18th March 2012, 03:23 PM
|
|
Registered User
|
|
Join Date: Nov 2011
Posts: 35

|
|
|
Re: trouble with python script and cron
under cron, the environment is much less complete than a normal shell.
Use full paths everywhere, and remove any tilde (~) stuff.
|

18th March 2012, 03:24 PM
|
|
Registered User
|
|
Join Date: Feb 2012
Location: Canterbury, Kent, UK
Posts: 5

|
|
|
Re: trouble with python script and cron
Quote:
Originally Posted by Alberth5674764
under cron, the environment is much less complete than a normal shell.
Use full paths everywhere, and remove any tilde (~) stuff.
|
Yeah, I did that, both within the script itself and the crontab - I only used absolute paths!
Thanks anyway
|

18th March 2012, 03:31 PM
|
|
Registered User
|
|
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,105

|
|
|
Re: trouble with python script and cron
The process the cron process runs does not have access to the display, and cannot put anything on it.
All it could do is replace the default background in the configuration files.
The only way you can reliably get it to work is to run in the same context as the gnome shell - however you find any "auto-start" capabilities.
|

18th March 2012, 04:15 PM
|
|
Registered User
|
|
Join Date: Feb 2012
Location: Canterbury, Kent, UK
Posts: 5

|
|
|
Re: trouble with python script and cron
Quote:
Originally Posted by jpollard
The process the cron process runs does not have access to the display, and cannot put anything on it.
All it could do is replace the default background in the configuration files.
|
So, you're saying that when I run the command-line gsettings tool within the script it won't actually access the DE settings? Because I can run it from a shell and it works...
---------- Post added at 03:15 PM ---------- Previous post was at 02:37 PM ----------
Haha, all it took was to supply the command with the correct display (prefix DISPLAY=:0.0) and it is now working perfectly!
See here: http://fuzzytolerance.info/rotating-...3-with-python/ (I had already checked this blog entry in order to script gnome-shell actions in Python, but forgot to read the comments... shame on me!  )
Thanks for the tip, jpollard. One is always learning!
|

18th March 2012, 08:12 PM
|
 |
Registered User
|
|
Join Date: Jun 2004
Location: Laurel, MD USA
Posts: 5,449

|
|
|
Re: trouble with python script and cron
I still don't get why doing something in a loop once every couple minutes would use a lot of cpu time? The script would be sleeping nearly all the time and using nearly 0 cpu time.
|

18th March 2012, 10:22 PM
|
|
Registered User
|
|
Join Date: Aug 2009
Location: Waldorf, Maryland
Posts: 6,105

|
|
|
Re: trouble with python script and cron
Quote:
Originally Posted by manuelmarque
So, you're saying that when I run the command-line gsettings tool within the script it won't actually access the DE settings? Because I can run it from a shell and it works...
---------- Post added at 03:15 PM ---------- Previous post was at 02:37 PM ----------
Haha, all it took was to supply the command with the correct display (prefix DISPLAY=:0.0) and it is now working perfectly!
See here: http://fuzzytolerance.info/rotating-...3-with-python/ (I had already checked this blog entry in order to script gnome-shell actions in Python, but forgot to read the comments... shame on me!  )
|
It all depends on who is logged in. If you are the only user then that will work.... some times - If you are not logged in you get errors. If someone else is logged in (or you as someone else) more errors.
|

18th March 2012, 11:03 PM
|
|
Registered User
|
|
Join Date: Feb 2012
Location: Canterbury, Kent, UK
Posts: 5

|
|
|
Re: trouble with python script and cron
Quote:
Originally Posted by jpollard
It all depends on who is logged in. If you are the only user then that will work.... some times - If you are not logged in you get errors. If someone else is logged in (or you as someone else) more errors.
|
OK, thanks for the tip! But since this is my personal computer in which I am the sole user (and I don't intend to run a graphical session as root) I think I won't run into further problems...
Regarding marko's post (I thought I had replied but the post is not here, something failed... :P) - I had initially set the script to do the timing by itself (every 45 minutes or so it would then run the function to rotate the wallpaper) but since I didn't know about the timer.sleep() function I did what every newbie would do: while True and everything inside the loop! (which is good if you're programming a microcontroller which will only do that little piece of code, but it is *not* OK for a daemon which we want to have the minimum possible impact on the system! :P)
Which was the main reason I switched to a cron-based solution and left the timing chores to the OS - a more clever solution, if you ask me! 
---------- Post added at 10:03 PM ---------- Previous post was at 09:35 PM ----------
Quote:
Originally Posted by marko
I think there are already gnome plugins and KDE plasma widgets that will do wallpaper rotation for you. That might be a good thing to look into also
|
Hmmm, I checked the main gnome extensions website and found nothing on that... and I'm not that huge fan of KDE, so I wouldn't go that way either (KDE _does_ have multiple image support for the wallpaper built-in, I think...).
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
Current GMT-time: 22:20 (Wednesday, 22-05-2013)
|
|
 |
 |
 |
 |
|
|