rebooting from within python sketch

I am trying to reboot the yun from within a python sketch running on the linux side. I can successfully reboot from the linux prompt by simply typing "reboot", but neither this code:

command = "reboot"
import subprocess
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)

or this code:

import os
os.system('reboot')

seem to work from within python.

Ideas?

root@Arduino:/mnt/sda1# /sbin/reboot --help
BusyBox v1.19.4 (2014-09-03 19:18:17 CEST) multi-call binary.
Usage: reboot [-d DELAY] [-n] [-f]
Reboot the system
        -d SEC  Delay interval
        -n      Do not sync
        -f      Force (don't go through init)
nano reboot.py
command = "/sbin/reboot -n -f"
import subprocess
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
python reboot.py

Use absolute path

ok that works as a stand alone sketch, but if I put the code in a function and call it in python, nothing happens. In other words if I run this program:

def rebootScript():

	print "rebooting system"
	command = "/sbin/reboot -n -f"
	import subprocess
	process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
	output = process.communicate()[0]
	print output
	return 
print "calling reboot script"
rebootScript
print "returned from reboot script"

I get the the following output:

calling reboot script
returned from reboot script

but the processor does not reboot, and I am back at the unix prompt.

What gives?

I think inside the function you might need to use the multiprocessing instead of subprocess.

But just for reboot machine, just stay inline code if I were you.

I need to run it from a function. What module is the multiprocessing?

"multiprocessing" is the module for multiprocessing. but you need compile it yourself since it does not come with YunOS. multiprocessing comes with python-full which pre-installed at Yun.

Ok,

can you give me an example of how I could reboot from inside a function using multiprocessing?

import multiprocessing

def rebootScript():
	command = "/sbin/reboot -n -f"
	import subprocess
	process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
	return 

if __name__ == '__main__':
        p = multiprocessing.Process(target=rebootScript)
        p.start()

Actually, no need to us multiprocess. My error was not including the parentheses after the call to the function.

I had

rebootScript

when I should have had

rebootScript()