-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
40 lines (32 loc) · 1.04 KB
/
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
# -*- coding: utf-8 -*-
from __future__ import unicode_literals, division
import argparse
import imp
from time import sleep
def run_remote(data=None, func=None):
try:
func.next()
while True:
data = func.send(data)
func.next()
except StopIteration:
return StopIteration
except KeyboardInterrupt:
return data
if __name__ == '__main__':
parser = argparse.ArgumentParser(description='run cooperative code')
parser.add_argument('file_path', metavar='file_path', type=str, help='file to run')
args = parser.parse_args()
data = None
while True:
data = run_remote(data, func=imp.load_source('contained', args.file_path).run())
if data is StopIteration:
print 'byebye'
break
else:
print 'You have 2s to Keyboard interrupt the program for real. Otherwise, it will be reloaded and resumed'
try:
sleep(2)
except KeyboardInterrupt:
print 'byebye'
break