Im attempting to perform an if statement at a certain time but can't get it to execute when it is that time. I am running the program when it reaches that time and nothing happens.  import os import datetime  now = datetime.datetime.now()  if now.hour == 20 and now.minute == 46:     print ("REBOOTING")     os.system("shutdown -t 0 -r -f")
14010
I'm looking for a library in Python which will provide at and cron like functionality.  I'd quite like have a pure Python solution, rather than relying on tools installed on the box; this way I run on machines with no cron.  For those unfamiliar with cron: you can schedule tasks based upon an expression like:    0 2 * * 7 /usr/bin/run-backup # run the backups at 0200 on Every Sunday  0 9-17/2 * * 1-5 /usr/bin/purge-temps # run the purge temps command, every 2 hours between 9am and 5pm on Mondays to Fridays.   The cron time expression syntax is less important, but I would like to have something with this sort of flexibility.   If there isn't something that does this for me out-the-box, any suggestions for the building blocks to make something like this would be gratefully received.  Edit I'm not interested in launching processes, just "jobs" also written in Python - python functions. By necessity I think this would be a different thread, but not in a different process.  To this end, I'm looking for the expressivity of the cron time expression, but in Python.   Cron has been around for years, but I'm trying to be as portable as possible. I cannot rely on its presence.
92316
I am working on a formula based on a date/time value to extract the time for the field. This field is based on the Pacific Time Zone and as is appears as  04/04/2016 9:00 PM  I set up this formula below  LEFT(RIGHT(text(  HOC__End_Date_Time__c ),9),7)  However the return result is based on GMT and returns based on a 24-hour clock, is there a way to adjust so it can simply display as 9:00 PM rather than as 24:00.  Hope it helps.
25510
My pc runs a program when it boots. Sometimes the program stops working after a few hours, but it will work fine when it reboots. So, I want to schedule my pc to reboot every 3 hours to prevent the program to be stopped. I'm using Ubuntu 14.04.  edit: The program doesn't stop, it just doesn't work with the maximum power of the pc but I need it to work with full power.
24812
Given a datetime.time value in Python, is there a standard way to add an integer number of seconds to it, so that 11:34:59 + 3 = 11:35:02, for example?  These obvious ideas don't work:  &gt;&gt;&gt; datetime.time(11, 34, 59) + 3 TypeError: unsupported operand type(s) for +: 'datetime.time' and 'int' &gt;&gt;&gt; datetime.time(11, 34, 59) + datetime.timedelta(0, 3) TypeError: unsupported operand type(s) for +: 'datetime.time' and 'datetime.timedelta' &gt;&gt;&gt; datetime.time(11, 34, 59) + datetime.time(0, 0, 3) TypeError: unsupported operand type(s) for +: 'datetime.time' and 'datetime.time'   In the end I have written functions like this:  def add_secs_to_time(timeval, secs_to_add):     secs = timeval.hour * 3600 + timeval.minute * 60 + timeval.second     secs += secs_to_add     return datetime.time(secs // 3600, (secs % 3600) // 60, secs % 60)   I can't help thinking that I'm missing an easier way to do this though.  Related
11596
I often move between 2 time zones, and expect my Windows 7 laptop to somehow automatically change the system time, being spoiled by the same feature on my cell phone. I always assumed that desktop O/Ses simply did not do this, but I was shocked yesterday when I noticed that OSX on the MacBook actually does this!  Does anybody know of any utilities that does this on Windows, specifically Windows 7? There has to be something out there?
52980
I want to set a variable if my condition is true on my Ubuntu system.  This proves that my if-statement is correct:  $ (if [ 1 == 1 ]; then echo "hi there"; fi); hi there   This proves that I can set variables:  $ a=1 $ echo $a 1   This shows that setting a variable in the if-statement DOES NOT work:  $ (if [ 1 == 1 ]; then a=2; fi); $ echo $a 1   Any ideas why? All my  indicates that it should work like this...
103713
Trying to create an alarm of sorts.  Task runs fine, computer wakes up from sleep fine, but the screen's black till there's user input. Anyway I can get the screen to light up upon waking?
101488
Alright, quick question.  A server is running in Eastern Time. PHP program needs to make date calculations using Central time.  At the moment, I am putting this line at the very top of my script:  putenv("TZ=US/Central");   Is that the best way to go about that or is there some PHP trick I'm not aware of?  Cheers.
22644
I have a console app in which I want to give the user x seconds to respond to the prompt.  If no input is made after a certain period of time, program logic should continue.  We assume a timeout means empty response.  What is the most straightforward way of approaching this?
96044
I am talking about events taking place in the known future:     Would it be okay if I'll confirm around 3 pm?   or should it be      Would it be okay if I'd confirm around 3 pm?   What is the difference and which one is correct? Why?
16336
Given the following code (that doesn't work):  while True:     #snip: print out current state     while True:         ok = get_input("Is this ok? (y/n)")         if ok.lower() == "y": break 2 #this doesn't work :(         if ok.lower() == "n": break     #do more processing with menus and stuff   Is there a way to make this work? Or do I have do one check to break out of the input loop, then another, more limited, check in the outside loop to break out all together if the user is satisfied?
110789
If nothing happens on the status after 24 hours, the lead should be reassigned to the Telesales Director and my workflow rule criteria is NOT( ISCHANGED( Status ) )    = DATEVALUE(( TODAY() ) + 24) Please help me because I am having an error
3567
Given the following code, what does the if __name__ == "__main__": do?  # Threading example import time, thread  def myfunction(string, sleeptime, lock, *args):     while True:         lock.acquire()         time.sleep(sleeptime)         lock.release()         time.sleep(sleeptime)  if __name__ == "__main__":     lock = thread.allocate_lock()     thread.start_new_thread(myfunction, ("Thread #: 1", 2, lock))     thread.start_new_thread(myfunction, ("Thread #: 2", 2, lock))
4303
I want to repeatedly execute a function in Python every 60 seconds forever (just like an  in Objective C). This code will run as a daemon and is effectively like calling the python script every minute using a cron, but without requiring that to be set up by the user.  In , the solution appears to effectively just  for x seconds. I don't need such advanced functionality so perhaps something like this would work  while True:     # Code executed here     time.sleep(60)   Are there any foreseeable problems with this code?
59914
I want to start a process from a shell script, allow it to interact with the user (so I cannot just background it, grab the PID, launch sleep followed by sanity checks and kill), but if it is still running after a set period of time (say, two minutes), then and only then do I want to kill it.  The intention is to simply implement a wallclock-run-time timeout for a program that doesn't have that capability built in.  Is there a way to do this, preferably from a bash shell script?
72755
I would like Ubuntu to automatically synchronize my system clock with a timeserver at startup.  However, my PC isn't connected to the Internet until after I've logged in (plus 5 - 10 seconds for good measure).  How can I set it to do this?
44039
I am looking to calculate time difference between the two below  Value1=2016-10-13 14:19:23 Value2=2016-10-13 18:19:23    I want to get difference in the form of hours/minutes. Any quick solution available?.