Beremiz_service.py
changeset 2738 58f2e3f22934
parent 2669 be233279d179
child 3282 725d3e9ac913
equal deleted inserted replaced
2737:38afed869ff6 2738:58f2e3f22934
   544             WC.RegisterWampClient(wampconf, PSKpath)
   544             WC.RegisterWampClient(wampconf, PSKpath)
   545             WC.RegisterWebSettings(NS)
   545             WC.RegisterWebSettings(NS)
   546         except Exception:
   546         except Exception:
   547             LogMessageAndException(_("WAMP client startup failed. "))
   547             LogMessageAndException(_("WAMP client startup failed. "))
   548 
   548 
   549 pyro_thread_started = Lock()
   549 def FirstWorkerJob():
   550 pyro_thread_started.acquire()
   550     """
   551 pyro_thread = Thread(target=pyroserver.PyroLoop,
   551     RPC through pyro/wamp/UI may lead to delegation to Worker,
   552                      kwargs=dict(when_ready=pyro_thread_started.release),
   552     then this function ensures that Worker is already
   553                      name="PyroThread")
   553     created when pyro starts
   554 pyro_thread.start()
   554     """
   555 
   555     global pyro_thread, pyroserver, ui_thread, reactor, twisted_reactor_thread_id
   556 # Wait for pyro thread to be effective
   556 
   557 pyro_thread_started.acquire()
   557     pyro_thread_started = Lock()
   558 
   558     pyro_thread_started.acquire()
   559 pyroserver.PrintServerInfo()
   559     pyro_thread = Thread(target=pyroserver.PyroLoop,
   560 
   560                          kwargs=dict(when_ready=pyro_thread_started.release),
   561 # Beremiz IDE detects LOCAL:// runtime is ready by looking
   561                          name="PyroThread")
   562 # for self.workdir in the daemon's stdout.
   562 
   563 sys.stdout.write(_("Current working directory :") + WorkingDir + "\n")
   563     pyro_thread.start()
   564 sys.stdout.flush()
   564 
   565 
   565     # Wait for pyro thread to be effective
   566 if havetwisted or havewx:
   566     pyro_thread_started.acquire()
       
   567 
       
   568     pyroserver.PrintServerInfo()
       
   569 
       
   570     # Beremiz IDE detects LOCAL:// runtime is ready by looking
       
   571     # for self.workdir in the daemon's stdout.
       
   572     sys.stdout.write(_("Current working directory :") + WorkingDir + "\n")
       
   573     sys.stdout.flush()
       
   574 
       
   575     if not (havetwisted or havewx):
       
   576         return
       
   577 
   567     ui_thread_started = Lock()
   578     ui_thread_started = Lock()
   568     ui_thread_started.acquire()
   579     ui_thread_started.acquire()
   569     if havetwisted:
   580     if havetwisted:
   570         # reactor._installSignalHandlersAgain()
   581         # reactor._installSignalHandlersAgain()
   571         def ui_thread_target():
   582         def ui_thread_target():
   590 
   601 
   591     # Wait for ui thread to be effective
   602     # Wait for ui thread to be effective
   592     ui_thread_started.acquire()
   603     ui_thread_started.acquire()
   593     print("UI thread started successfully.")
   604     print("UI thread started successfully.")
   594 
   605 
       
   606     runtime.GetPLCObjectSingleton().AutoLoad(autostart)
       
   607 
   595 try:
   608 try:
   596     runtime.MainWorker.runloop(
   609     runtime.MainWorker.runloop(FirstWorkerJob)
   597         runtime.GetPLCObjectSingleton().AutoLoad, autostart)
       
   598 except KeyboardInterrupt:
   610 except KeyboardInterrupt:
   599     pass
   611     pass
   600 
   612 
   601 pyroserver.Quit()
   613 pyroserver.Quit()
   602 pyro_thread.join()
   614 pyro_thread.join()