utilize os The module can perform cmd command , This can be used to achieve a timed shutdown , However, you can't do nothing while waiting for the shutdown , So multithreading comes in handy .
#! /usr/bin/env python
#coding=utf-8
# Three modules need to be introduced here
import time, os, sched, easygui, thread
# The first parameter determines the time of the task , Returns the number of seconds elapsed from a specific time to the present
# The second parameter measures time in some artificial way
schedule = sched.scheduler(time.time, time.sleep)
def perform_command(cmd, inc):
os.system(cmd)
def reminder(cmd, inc = 60):
# enter Used to schedule an event , From now on n Start in seconds
schedule.enter(inc, 0, perform_command, (cmd, inc))
# Keep running , Until the scheduled time queue becomes empty
schedule.run()
thread.exit_thread()
if __name__=='__main__':
print("show time after 10 seconds:")
thread.start_new_thread(reminder, ("shutdown -s", 10))
print' In the process of waiting, it doesn't delay us to do something else ' </pre>