0

Is there a way, within the context of a Python interpreter, to set the clock (i.e. to synchronize it with the time provided by time.windows.com), such that:

  1. any function querying the current time within the environment of that interpreter instance (i.e. datetime.now()), will show the newly-set time

  2. the system's time settings outside of the interpreter environment are not affected (i.e. there is no change to the hardware clock)

Basically, the idea is to trick everything within the interpreter instance to believe that the current time is something other than the time to which the system on which the interpreter is running, is set (unless the newly-specified time happens to coincide with the system clock). Assuming it's possible, any suggestions on how to do this?

Boa
  • 2,609
  • 1
  • 23
  • 38
  • You could use Docker – Wayne Werner Sep 29 '16 at 17:40
  • [`freezegun`](https://github.com/spulec/freezegun) is a third-party library that can do similar stuff. It's mostly only meant to be used in tests (and I'm hoping that's the use-case here)... – mgilson Sep 29 '16 at 17:40
  • Otherwise, yeah, you're pretty much left monkeypatching everything – Wayne Werner Sep 29 '16 at 17:41
  • @WayneWerner - Thanks, guys. Actually, I'm just exploring options on how to solve a Twitter API 401 error, which can result from system clock configuration issues: https://stackoverflow.com/questions/39758666/401-error-using-the-streaming-features-of-twitter-api-through-tweepy. It sounds like I'll have to look for an approach that's more specific to the functionality that interacts with Twitter's API. – Boa Sep 29 '16 at 17:47

0 Answers0