432 print "Twisted unavailable." |
432 print "Twisted unavailable." |
433 havetwisted = False |
433 havetwisted = False |
434 |
434 |
435 pyruntimevars = {} |
435 pyruntimevars = {} |
436 statuschange = [] |
436 statuschange = [] |
437 registerserverto = [] |
|
438 |
437 |
439 if havetwisted: |
438 if havetwisted: |
440 |
439 |
441 if havewx: |
440 if havewx: |
442 reactor.registerWxApp(app) |
441 reactor.registerWxApp(app) |
443 |
|
444 if webport is not None : |
|
445 try: |
|
446 import runtime.NevowServer as NS |
|
447 website = NS.RegisterWebsite(webport) |
|
448 pyruntimevars["website"] = website |
|
449 statuschange.append(NS.website_statuslistener_factory(website)) |
|
450 except Exception, e: |
|
451 print "Nevow Web service failed.", e |
|
452 |
|
453 if wampconf is not None : |
|
454 try: |
|
455 import runtime.WampClient as WC |
|
456 WC.RegisterWampClient(wampconf) |
|
457 pyruntimevars["wampsession"] = WC.GetSession |
|
458 registerserverto.append(WC.SetServer) |
|
459 except Exception, e: |
|
460 print "WAMP client startup failed.", e |
|
461 |
442 |
462 if havewx: |
443 if havewx: |
463 from threading import Semaphore |
444 from threading import Semaphore |
464 wx_eval_lock = Semaphore(0) |
445 wx_eval_lock = Semaphore(0) |
465 main_thread = currentThread() |
446 main_thread = currentThread() |
493 else: |
474 else: |
494 pyroserver = Server(servicename, given_ip, port, |
475 pyroserver = Server(servicename, given_ip, port, |
495 WorkingDir, argv, autostart, |
476 WorkingDir, argv, autostart, |
496 statuschange, pyruntimevars=pyruntimevars) |
477 statuschange, pyruntimevars=pyruntimevars) |
497 |
478 |
498 for registrar in registerserverto : |
|
499 registrar(pyroserver) |
|
500 |
479 |
501 # Exception hooks s |
480 # Exception hooks s |
502 import threading, traceback |
481 import threading, traceback |
503 def LogException(*exp): |
482 def LogException(*exp): |
504 if pyroserver.plcobj is not None: |
483 if pyroserver.plcobj is not None: |
521 sys.excepthook(*sys.exc_info()) |
500 sys.excepthook(*sys.exc_info()) |
522 self.run = run_with_except_hook |
501 self.run = run_with_except_hook |
523 threading.Thread.__init__ = init |
502 threading.Thread.__init__ = init |
524 installThreadExcepthook() |
503 installThreadExcepthook() |
525 |
504 |
|
505 if havetwisted: |
|
506 if webport is not None : |
|
507 try: |
|
508 import runtime.NevowServer as NS |
|
509 except Exception, e: |
|
510 print "Nevow/Athena import failed :", e |
|
511 webport = None |
|
512 |
|
513 if wampconf is not None : |
|
514 try: |
|
515 import runtime.WampClient as WC |
|
516 except Exception, e: |
|
517 print "WAMP import failed :", e |
|
518 wampconf = None |
|
519 |
526 # Load extensions |
520 # Load extensions |
527 for extfilename in extensions: |
521 for extfilename in extensions: |
528 extension_folder = os.path.split(os.path.realpath(extfilename))[0] |
522 extension_folder = os.path.split(os.path.realpath(extfilename))[0] |
529 sys.path.append(extension_folder) |
523 sys.path.append(extension_folder) |
530 execfile(extfilename, locals()) |
524 execfile(extfilename, locals()) |
|
525 |
|
526 if havetwisted: |
|
527 if webport is not None : |
|
528 try: |
|
529 website = NS.RegisterWebsite(webport) |
|
530 pyruntimevars["website"] = website |
|
531 statuschange.append(NS.website_statuslistener_factory(website)) |
|
532 except Exception, e: |
|
533 print "Nevow Web service failed.", e |
|
534 |
|
535 if wampconf is not None : |
|
536 try: |
|
537 WC.RegisterWampClient(wampconf) |
|
538 pyruntimevars["wampsession"] = WC.GetSession |
|
539 WC.SetServer(pyroserver) |
|
540 except Exception, e: |
|
541 print "WAMP client startup failed.", e |
|
542 |
531 |
543 |
532 if havetwisted or havewx: |
544 if havetwisted or havewx: |
533 pyro_thread=Thread(target=pyroserver.Loop) |
545 pyro_thread=Thread(target=pyroserver.Loop) |
534 pyro_thread.start() |
546 pyro_thread.start() |
535 |
547 |