fix: [errorHandling] more try catch error

pull/97/head
Steve Clement 2019-05-29 09:48:26 +09:00
parent 30cb762ef7
commit fc1c832420
No known key found for this signature in database
GPG Key ID: 69A20F509BE4AEE9
2 changed files with 20 additions and 4 deletions

View File

@ -27,7 +27,12 @@ logfilename = cfg.get('Log', 'filename')
logPath = os.path.join(logDir, logfilename)
if not os.path.exists(logDir):
os.makedirs(logDir)
logging.basicConfig(filename=logPath, filemode='a', level=logging.INFO)
try:
logging.basicConfig(filename=logPath, filemode='a', level=logging.INFO)
except PermissionError as error:
print(error)
print("Please fix the above and try again.")
sys.exit(126)
logger = logging.getLogger('zmq_dispatcher')
LISTNAME = cfg.get('RedisLIST', 'listName')
@ -289,4 +294,7 @@ if __name__ == "__main__":
parser.add_argument('-s', '--sleep', required=False, dest='sleeptime', type=int, help='The number of second to wait before checking redis list size', default=5)
args = parser.parse_args()
main(args.sleeptime)
try:
main(args.sleeptime)
except redis.exceptions.ResponseError as error:
print(error)

View File

@ -20,7 +20,12 @@ logfilename = cfg.get('Log', 'filename')
logPath = os.path.join(logDir, logfilename)
if not os.path.exists(logDir):
os.makedirs(logDir)
logging.basicConfig(filename=logPath, filemode='a', level=logging.INFO)
try:
logging.basicConfig(filename=logPath, filemode='a', level=logging.INFO)
except PermissionError as error:
print(error)
print("Please fix the above and try again.")
sys.exit(126)
logger = logging.getLogger('zmq_subscriber')
ZMQ_URL = cfg.get('RedisGlobal', 'zmq_url')
@ -64,4 +69,7 @@ if __name__ == "__main__":
parser.add_argument('-u', '--url', required=False, dest='zmqurl', help='The URL to connect to', default=ZMQ_URL)
args = parser.parse_args()
main(args.zmqname)
try:
main(args.zmqname)
except redis.exceptions.ResponseError as error:
print(error)