Q:

how can I restart the computer from python script and make the script automatically continue from where it stopped?

I would like to write a python script executing some command.
After some commands I want to reboot the computer (through the script) ,so that the script will continue automatically from where it stopped. 
if there's a way to do so thruogh the command line, it will also be helpful, because I can run subprocess.
Thanks!!

A:

It isn't possible to do this "automatically", you need to record some notion of the program's state when the computer shuts down. Conceptually this is no different than having the program exit, then running it again and picking up where it left off (without rebooting).
There are a number of different ways to save state, broadly called serialization. In Python, two common options for serialization are the JSON text format and "pickling", which lets you serialize a Python data structure.
How exactly you serialize your program's state depends on your requirements, but once you've done that you can restart your program (or the whole computer), read in the saved data, and use that to continue progressing from that point.
Shutting down (and running a program at startup) are OS-dependent operations, so you need to provide more context about what environment you're working in to answer more clearly. In Unix you can generally call reboot or sudo reboot to restart your computer.

