blob: 8b79403730aa624f57abfd5ac80176e0d733b145 (
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
|
# python import
import atexit, multiprocessing
# olpcfr import
from olpcfr import config
class Server(object):
def __init__(self):
from olpcfr.flask import app, run_app
if app:
# start the server
self._server = multiprocessing.Process(target=run_app)
self._server.start()
# .. required to close properly
atexit.register(self.close)
else:
# .. nothing to start
self._server = None
def close(self):
# stop web thread if started
if self._server:
self._server.terminate()
self._server.join()
|