Commit c4add9b8 authored by Marius Isken's avatar Marius Isken
Browse files

BaraddurProcess // Added first implementation

parent c25df056
......@@ -8,8 +8,11 @@ setup(
version='0.1',
author='Sebastian Heimann',
author_email='sebastian.heimann@gfz-potsdam.de',
packages=['grond'],
package_dir={'grond': 'src'},
packages=['grond', 'grond.baraddur'],
scripts=['apps/grond'],
package_data={'grond': []},
data_files=[('/etc/bash_completion.d', ['extras/grond'])])
package_dir={'grond': 'src'},
package_data={'grond': [],
'grond': ['baraddur/templates/*.html',
'baraddur/css/*']},
data_files=[('/etc/bash_completion.d', ['extras/grond'])],
)
from .server import # noqa
\ No newline at end of file
import multiprocessing as _mp
import signal as _signal
from .server import Baraddur # noqa
class BaraddurProcess(_mp.Process):
def __init__(self, *args, **kwargs):
self.server = Baraddur(*args, **kwargs)
self.shutdown_signal = _mp.Queue(1)
_mp.Process.__init__(self)
_signal.signal(_signal.SIGINT, self.server.stop)
def run(self):
self.server.start(signal=self.shutdown_signal)
def stop(self):
self.shutdown_signal.put(True)
if __name__ == '__main__':
p = BaraddurProcess('/home/marius/Development/testing/grond/rundir')
p.start()
......@@ -282,12 +282,8 @@ pages = OrderedDict([
class BaraddurConfig(Object):
rundir = String.T(
help='Grond rundir.')
template_path = String.T(
default='templates',
optional=True,
help='Baraddur templates.')
debug = Bool.T(
default=True,
default=False,
optional=True)
hosts = List.T(
String.T(),
......@@ -307,6 +303,8 @@ class BaraddurConfig(Object):
class Baraddur(BokehServer):
def __init__(self, rundir=None, *args, **kwargs):
self.config = BaraddurConfig(rundir=rundir)
print self.config
self.ioloop = tornado.ioloop.IOLoop.current()
port_offset = 0
while True:
......@@ -314,7 +312,7 @@ class Baraddur(BokehServer):
BokehServer.__init__(
self,
self.get_bokeh_apps(),
io_loop=tornado.ioloop.IOLoop.current(),
io_loop=self.ioloop,
extra_patterns=self.get_tornado_handlers(),
port=self.config.port + port_offset,
host=self.config.hosts)
......@@ -327,11 +325,9 @@ class Baraddur(BokehServer):
self.config.port + port_offset))
else:
raise se
logger.info('Created Baraddur server on http://localhost:%d'
% (self.port))
tornado_app = self._tornado
tornado_app.settings['template_path'] = self.config.template_path
tornado_app.settings['template_path'] = op.join(
op.dirname(op.abspath(__file__)), 'templates')
if self.config.debug:
tornado_app.settings.setdefault('autoreload', True)
......@@ -366,12 +362,28 @@ class Baraddur(BokehServer):
[(r'/css/(.*)', StaticFileHandler,
{'path': op.join(op.dirname(__file__), 'css')})]
def start(self):
def start(self, signal=None):
logger.info('Starting Baraddur server on http://localhost:%d'
% (self.port))
if signal is not None:
def shutdown():
if not signal.empty():
self.stop()
tornado.ioloop.PeriodicCallback(shutdown, 2000).start()
BokehServer.start(self)
tornado.ioloop.IOLoop.current().start()
self.ioloop.start()
def stop(self, *args, **kwargs):
print args, kwargs
logger.info('Stopping Baraddur server...')
BokehServer.stop(self)
self.ioloop.stop()
if __name__ == '__main__':
if __name__ == '_123_main__':
baraddur = Baraddur(
rundir='/home/marius/Development/testing/grond/rundir')
baraddur.start()
print 'here!'
......@@ -142,7 +142,7 @@ def load_problem_info(dirname):
def load_problem_data(dirname, problem, skip_models=0):
fn = op.join(dirname, 'x')
fn = op.join(dirname, 'models')
with open(fn, 'r') as f:
nmodels = os.fstat(f.fileno()).st_size / (problem.nparameters * 8)
nmodels -= skip_models
......@@ -965,13 +965,16 @@ g_state = {}
def go(config, event_names=None, force=False, nparallel=1, status=('state',)):
status = tuple(status)
g_data = (config, force, status, nparallel, event_names)
g_state[id(g_data)] = g_data
nevents = len(event_names)
from .baraddur import BaraddurProcess
baraddur = BaraddurProcess(rundir=expand_template(config.rundir_template,
event_names[0]))
baraddur.start()
for x in parimap.parimap(
process_event,
xrange(nevents),
......@@ -979,6 +982,9 @@ def go(config, event_names=None, force=False, nparallel=1, status=('state',)):
nprocs=nparallel):
pass
logger.info('Grond finished processing %d events. '
'Ctrl+C to kill Barad-dur')
baraddur.join()
def process_event(ievent, g_data_id):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment