-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·47 lines (35 loc) · 869 Bytes
/
run.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env python
import os
import sys
import time
import fcntl
import signal
import pygame
import traceback
from BB8 import BB8
if os.geteuid() != 0:
print "This script must be run with sudo."
sys.exit(1)
procs = os.popen("sudo ps ax | grep python").read().split("\n")
for proc in procs:
if "run.py" in proc:
pid = int(proc.lstrip(" ").split(" ")[0])
if pid != os.getpid():
os.system("sudo kill " + str(pid))
time.sleep(1)
bb8 = BB8()
def handler(signal, frame):
bb8.Exit()
sys.exit(0)
signal.signal(signal.SIGTERM, handler)
def running():
bb8.Update()
return True
def run(script):
exec(open(os.path.realpath(script)).read(), { "running": running, "bb8": bb8 })
running()
for script in sys.argv[1:]:
run(script)
clock = pygame.time.Clock()
while running():
clock.tick(50)