The OS module can be used to execute the cmd command, which can be used to achieve a timed shutdown, but in the process of waiting for shutdown can not do nothing, so multi-threading comes in handy.
#! /usr/bin/env python#coding=utf-8# here need to introduce three modules import time, OS, sched, Easygui, Thread # The first parameter determines when a task is Returns the number of seconds 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 = $): # Enter is used to schedule the occurrence of an event, starting from now on in nth Seconds Schedule.enter (inc, 0, Perform_command, (CMD, Inc) # continues to run until the scheduled time queue becomes empty schedule.run () thread.exit_thread () if __name__ = = ' __main__ ': print ("Show Time After Seconds:") Thread.start_new_thread (Reminder, ("Shutdown-s", 10)) print ' In this waiting process does not delay us doing something else '
Python executes cmd command shutdown with multithreading timing