536 |
536 |
537 |
537 |
538 # Exception hooks s |
538 # Exception hooks s |
539 |
539 |
540 |
540 |
|
541 |
|
542 def LogMessageAndException(msg, exp=None): |
|
543 if exp is None: |
|
544 exp = sys.exc_info() |
|
545 if pyroserver.plcobj is not None: |
|
546 pyroserver.plcobj.LogMessage(0, msg + '\n'.join(traceback.format_exception(*exp))) |
|
547 else: |
|
548 print(msg) |
|
549 traceback.print_exception(*exp) |
|
550 |
541 def LogException(*exp): |
551 def LogException(*exp): |
542 if pyroserver.plcobj is not None: |
552 LogExceptionAndMessage("",exp) |
543 pyroserver.plcobj.LogMessage(0, '\n'.join(traceback.format_exception(*exp))) |
|
544 else: |
|
545 traceback.print_exception(*exp) |
|
546 |
|
547 |
553 |
548 sys.excepthook = LogException |
554 sys.excepthook = LogException |
549 |
555 |
550 |
556 |
551 def installThreadExcepthook(): |
557 def installThreadExcepthook(): |
598 if webport is not None: |
604 if webport is not None: |
599 try: |
605 try: |
600 website = NS.RegisterWebsite(webport) |
606 website = NS.RegisterWebsite(webport) |
601 pyruntimevars["website"] = website |
607 pyruntimevars["website"] = website |
602 statuschange.append(NS.website_statuslistener_factory(website)) |
608 statuschange.append(NS.website_statuslistener_factory(website)) |
603 except Exception, e: |
609 except Exception: |
604 print(_("Nevow Web service failed. "), e) |
610 LogMessageAndException(_("Nevow Web service failed. ")) |
605 |
611 |
606 if wampconf is not None: |
612 if wampconf is not None: |
607 try: |
613 try: |
608 _wampconf = WC.LoadWampClientConf(wampconf) |
614 _wampconf = WC.LoadWampClientConf(wampconf) |
609 if _wampconf: |
615 if _wampconf: |
610 if _wampconf["url"]: # TODO : test more ? |
616 if _wampconf["url"]: # TODO : test more ? |
611 WC.RegisterWampClient(wampconf, wampsecret) |
617 WC.RegisterWampClient(wampconf, wampsecret) |
612 pyruntimevars["wampsession"] = WC.GetSession |
618 pyruntimevars["wampsession"] = WC.GetSession |
613 WC.SetServer(pyroserver) |
619 WC.SetServer(pyroserver) |
614 else: |
620 else: |
615 print(_("WAMP config is incomplete.")) |
621 raise Exception(_("WAMP config is incomplete.")) |
616 else: |
622 else: |
617 print(_("WAMP config is missing.")) |
623 raise Exception(_("WAMP config is missing.")) |
618 except Exception, e: |
624 except Exception: |
619 print(_("WAMP client startup failed. "), e) |
625 LogMessageAndException(_("WAMP client startup failed. ")) |
620 |
626 |
621 |
627 |
622 if havetwisted or havewx: |
628 if havetwisted or havewx: |
623 pyro_thread = Thread(target=pyroserver.Loop) |
629 pyro_thread = Thread(target=pyroserver.Loop) |
624 pyro_thread.start() |
630 pyro_thread.start() |