Introduction
The following is a simple example of libfaketime.
It is often necessary to test the modification time in the work. If the environment does not allow the time to be adjusted, it is necessary to find a way to adjust the time of a single process.
Compile and install
git clone https://github.com/wolfcw/libfaketime.git
cd libfaketime && make install
python test script
test.py
import os
import time
import datetime
def set_time():
while True:
print(datetime.datetime.now())
time.sleep(2)
set_time()
shell set environment variables
#!/usr/bin/env bash
export LD_PRELOAD=/usr/local/lib/faketime/libfaketime.so.1
#export FAKETIME="2020-12-24 20:30:00" #该时间会一直保持不变
export FAKETIME="@2020-12-24 20:30:00" #时间会从这里往后递增
python ./test.py