Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Subprocess 丟出 exception 導致程式整個 halt 住 #41

Open
vava24680 opened this issue Dec 7, 2020 · 2 comments
Open

Subprocess 丟出 exception 導致程式整個 halt 住 #41

vava24680 opened this issue Dec 7, 2020 · 2 comments

Comments

@vava24680
Copy link
Contributor

  • 問題描述:當一開始 sa.py 中的 endpoint 打錯導致 requests 無法正常將 request 送到 EC 時,subprocess 會拋出 exception 但整個程式並不會中止而是 halt 住,需要多按一次 CTRL-C 才能終止
  • 執行環境:
    • OS: Debian 10
    • Python: CPython 3.7.3
    • iottalk-py version: 2.3.0
    • SA file which can re-produce the siuation:
      import random
      
      from iottalkpy.dan import NoData
      
      ### The registeration api url, you can use IP or Domain.
      # api_url = 'https://iottalk2.tw/csm'  # default
      api_url = 'http://GG/csm'  # with URL prefix
      # api_url = 'http://localhost:9992/csm'  # with URL prefix + port
      
      ### [OPTIONAL] If not given or None, server will auto-generate.
      device_name = 'Dummy_Test'
      
      ### [OPTIONAL] If not given or None, DAN will register using a random UUID.
      ### Or you can use following code to use MAC address for device_addr.
      from uuid import getnode
      # device_addr = "{:012X}".format(getnode())
      # device_addr = "..."
      
      ### [OPTIONAL] If the device_addr is set as a fixed value, user can enable
      ### this option and make the DA register/deregister without rebinding on GUI
      # persistent_binding = True
      
      ### [OPTIONAL] If not given or None, this device will be used by anyone.
      # username = 'myname'
      
      ### The Device Model in IoTtalk, please check IoTtalk document.
      device_model = 'Dummy_Device'
      
      ### The input/output device features, please check IoTtalk document.
      idf_list = ['Dummy_Sensor']
      odf_list = ['Dummy_Control']
      
      ### Set the push interval, default = 1 (sec)
      ### Or you can set to 0, and control in your feature input function.
      push_interval = 10  # global interval
      interval = {
          'Dummy_Sensor': 3,  # assign feature interval
      }
      
      
      def on_register(self):
          print('Register successfully')
      
      
      def Dummy_Sensor():
          return random.randint(0, 100)
      
          # Or you want to return nothing.
          # Note that the object `None` is treated as normal data in IoTtalk
          #
          # return NoData
      
      
      def Dummy_Control(data):  # data is a list
          print(str(data[0]))
@vava24680 vava24680 linked a pull request Dec 7, 2020 that will close this issue
@iblislin
Copy link
Member

iblislin commented Dec 7, 2020

這個問題也太詭異了吧

@vava24680
Copy link
Contributor Author

會發生的原因是目前的做法 master process 會 catch KeyboardInterrupt,但 child process 丟出 exception 終止時 master process 完全不知道,所以就 halt 住了

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants