57 lines
1.3 KiB
Python
57 lines
1.3 KiB
Python
|
from TestPublish import TestPublish
|
||
|
from TestSubscribe import TestSubscribe
|
||
|
from loguru import logger
|
||
|
import argparse
|
||
|
import configparser
|
||
|
import threading
|
||
|
|
||
|
|
||
|
deathBell = threading.Event()
|
||
|
|
||
|
def exceptHook(args):
|
||
|
global deathBell
|
||
|
logger.error("Exception in thread caught: {}".format(args))
|
||
|
deathBell.set()
|
||
|
logger.error("rang the death bell")
|
||
|
|
||
|
|
||
|
logger.info("example1 starting")
|
||
|
|
||
|
parser = argparse.ArgumentParser(description="example1")
|
||
|
parser.add_argument('--config', '-f',
|
||
|
help='Config file, default is $pwd/config.ini',
|
||
|
required=False,
|
||
|
default='./config.ini')
|
||
|
args = parser.parse_args()
|
||
|
|
||
|
config = configparser.ConfigParser()
|
||
|
config.read(args.config)
|
||
|
|
||
|
testSubscribeThread = TestSubscribe(config)
|
||
|
testSubscribeThread.start()
|
||
|
logger.info("testSubscribe started")
|
||
|
|
||
|
testPublishThread = TestPublish(config)
|
||
|
testPublishThread.start()
|
||
|
logger.info("testPublish started")
|
||
|
|
||
|
threading.excepthook = exceptHook
|
||
|
logger.info("Threading excepthook set")
|
||
|
|
||
|
logger.info("example1 is running")
|
||
|
|
||
|
|
||
|
deathBell.wait()
|
||
|
logger.error("example1 is dying")
|
||
|
|
||
|
testSubscribeThread.stop()
|
||
|
testPublishThread.stop()
|
||
|
|
||
|
testSubscribeThread.join()
|
||
|
logger.error("testSubscribe joined")
|
||
|
|
||
|
testPublishThread.join()
|
||
|
logger.error("testPublish joined")
|
||
|
|
||
|
logger.error("example1 is terminated")
|