blob: 2fc623c925e34b591be6e22e650b7a534f7d5400 (
plain)
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
|
import time
import rumba.log as log
import rumba.model as model
logger = log.get_logger(__name__)
class ExperimentManager(object):
PROMPT = 1
AUTO = 2
NO = 3
def __init__(self, experiment, do_swap_out=AUTO):
assert isinstance(experiment, model.Experiment), \
'An experiment instance is required.'
self.experiment = experiment
self.do_swap_out = do_swap_out
def __enter__(self):
pass
def __exit__(self, exc_type, exc_val, exc_tb):
if self.do_swap_out == self.PROMPT:
logger.info('Press ENTER to start swap out.')
input('')
if self.do_swap_out == self.PROMPT \
or self.do_swap_out == self.AUTO:
self.experiment.swap_out()
if exc_val is not None:
logger.error('Something went wrong. Got %s: %s',
type(exc_val).__name__, str(exc_val))
time.sleep(0.1) # Give the queue logger enough time to flush.
return True # Suppress the exception we logged: no traceback.
|