2014-11-30 19:16:27 +01:00
|
|
|
import Pyro4
|
2014-11-25 21:12:37 +01:00
|
|
|
import logging
|
2014-11-30 19:16:27 +01:00
|
|
|
|
|
|
|
Pyro4.config.REQUIRE_EXPOSE = True
|
2014-11-25 21:12:37 +01:00
|
|
|
log = logging.getLogger(__name__)
|
2014-08-31 13:45:35 +02:00
|
|
|
|
|
|
|
|
|
|
|
class CallbackServer(object):
|
|
|
|
|
2014-11-25 20:43:04 +01:00
|
|
|
def __init__(self, listen_port, remote_port):
|
2014-11-30 19:16:27 +01:00
|
|
|
self.daemon = Pyro4.Daemon(host='localhost', port=listen_port,
|
|
|
|
nathost='localhost', natport=remote_port,
|
2014-11-25 20:43:04 +01:00
|
|
|
unixsocket=None)
|
2014-11-30 19:16:27 +01:00
|
|
|
self.daemon.register(self)
|
2014-11-30 19:19:14 +01:00
|
|
|
self.abort = False
|
2014-08-31 13:45:35 +02:00
|
|
|
|
2014-11-30 19:16:27 +01:00
|
|
|
def start(self):
|
2014-08-31 13:45:35 +02:00
|
|
|
def serve():
|
2014-11-24 22:45:05 +01:00
|
|
|
self.daemon.requestLoop()
|
2014-08-31 13:45:35 +02:00
|
|
|
from threading import Thread
|
|
|
|
self.thread = Thread(target=serve)
|
2014-11-25 21:12:37 +01:00
|
|
|
log.debug('Starting the callback server')
|
2014-08-31 13:45:35 +02:00
|
|
|
self.thread.start()
|
|
|
|
|
|
|
|
def stop(self):
|
2014-11-25 20:43:23 +01:00
|
|
|
if hasattr(self, 'daemon'):
|
|
|
|
self.daemon.shutdown()
|
|
|
|
if hasattr(self, 'thread'):
|
|
|
|
self.thread.join()
|
2014-11-30 19:16:27 +01:00
|
|
|
|
|
|
|
@Pyro4.expose
|
|
|
|
def handle_log(self, pickled_record):
|
|
|
|
import pickle
|
|
|
|
record = pickle.loads(pickled_record)
|
|
|
|
log = logging.getLogger()
|
|
|
|
record.extra = getattr(record, 'extra', {})
|
|
|
|
record.extra['source'] = 'remote'
|
|
|
|
log.handle(record)
|
|
|
|
|
2014-11-30 19:19:14 +01:00
|
|
|
@Pyro4.expose
|
|
|
|
def get_abort_run(self):
|
|
|
|
return self.abort
|
|
|
|
|
|
|
|
def abort_run(self):
|
|
|
|
self.abort = True
|