prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Skills and Enclosure background services fail to stop and are killed...
  ## Be clear about the software, hardware and version you are running
  
  For example: 
  
  in CLI
   >> what version are you running                                                                                                                                               
   >> I am running mycroft-core version 20 oh 2, release 0                                                                                                                    
   >> You are on the latest version.
  
  Opensuse Leap 15.1
  ## Try to provide steps that we can use to replicate the Issue
  
  For example: 
  
  1. CTRL+C in CLI
  2. Enter ./stop_mycroft.sh 
  3. Skills and Enclosure services are eventually killed.
  4. Takes about 30 seconds total
  
  ## Be as specific as possible about the expected condition, and the deviation from expected condition. 
  
  user@LinuxOS:~/mycroft-core> ./stop-mycroft.sh skills
  Stopping skills (5579)...stopped.
  user@LinuxOS:~/mycroft-core> ./stop-mycroft.sh enclosure
  Stopping enclosure (5588)...failed to stop.
    Killing enclosure (5588)...killed.
  user@LinuxOS:~/mycroft-core> ./stop-mycroft.sh
  Stopping all mycroft-core services
  Stopping messagebus.service (5576)...stopped.
  Stopping audio (5582)...stopped.
  Stopping speech (5585)...stopped.
  ...
  user@LinuxOS:~/mycroft-core> ./stop-mycroft.sh
  Stopping all mycroft-core services
  Stopping messagebus.service (18995)...stopped.
  Stopping skills (18998)...failed to stop.
    Killing skills (18998)...killed.
  Stopping audio (19001)...stopped.
  Stopping speech (19004)...stopped.
  Stopping enclosure (19007)...failed to stop.
    Killing enclosure (19007)...killed.
  user@LinuxOS:~/mycroft-core> 
  
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `mycroft/client/enclosure/__main__.py`
  Content:
  ```
  1 # Copyright 2017 Mycroft AI Inc.
  2 #
  3 # Licensed under the Apache License, Version 2.0 (the "License");
  4 # you may not use this file except in compliance with the License.
  5 # You may obtain a copy of the License at
  6 #
  7 #    http://www.apache.org/licenses/LICENSE-2.0
  8 #
  9 # Unless required by applicable law or agreed to in writing, software
  10 # distributed under the License is distributed on an "AS IS" BASIS,
  11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12 # See the License for the specific language governing permissions and
  13 # limitations under the License.
  14 #
  15 import sys
  16 
  17 from mycroft.util.log import LOG
  18 from mycroft.messagebus.client import MessageBusClient
  19 from mycroft.configuration import Configuration, LocalConf, SYSTEM_CONFIG
  20 
  21 
  22 def main():
  23     # Read the system configuration
  24     system_config = LocalConf(SYSTEM_CONFIG)
  25     platform = system_config.get("enclosure", {}).get("platform")
  26 
  27     if platform == "mycroft_mark_1":
  28         LOG.debug("Creating Mark I Enclosure")
  29         from mycroft.client.enclosure.mark1 import EnclosureMark1
  30         enclosure = EnclosureMark1()
  31     elif platform == "mycroft_mark_2":
  32         LOG.debug("Creating Mark II Enclosure")
  33         from mycroft.client.enclosure.mark2 import EnclosureMark2
  34         enclosure = EnclosureMark2()
  35     else:
  36         LOG.debug("Creating generic enclosure, platform='{}'".format(platform))
  37 
  38         # TODO: Mechanism to load from elsewhere.  E.g. read a script path from
  39         # the mycroft.conf, then load/launch that script.
  40         from mycroft.client.enclosure.generic import EnclosureGeneric
  41         enclosure = EnclosureGeneric()
  42 
  43     if enclosure:
  44         try:
  45             LOG.debug("Enclosure started!")
  46             enclosure.run()
  47         except Exception as e:
  48             print(e)
  49         finally:
  50             sys.exit()
  51     else:
  52         LOG.debug("No enclosure available for this hardware, running headless")
  53 
  54 
  55 if __name__ == "__main__":
  56     main()
  57
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/mycroft/client/enclosure/__main__.py b/mycroft/client/enclosure/__main__.py
  --- a/mycroft/client/enclosure/__main__.py
  +++ b/mycroft/client/enclosure/__main__.py
  @@ -12,44 +12,67 @@
   # See the License for the specific language governing permissions and
   # limitations under the License.
   #
  -import sys
  +"""Entrypoint for enclosure service.
   
  +This provides any "enclosure" specific functionality, for example GUI or
  +control over the Mark-1 Faceplate.
  +"""
  +from mycroft.configuration import LocalConf, SYSTEM_CONFIG
   from mycroft.util.log import LOG
  -from mycroft.messagebus.client import MessageBusClient
  -from mycroft.configuration import Configuration, LocalConf, SYSTEM_CONFIG
  +from mycroft.util import (create_daemon, wait_for_exit_signal,
  +                          reset_sigint_handler)
   
   
  -def main():
  -    # Read the system configuration
  -    system_config = LocalConf(SYSTEM_CONFIG)
  -    platform = system_config.get("enclosure", {}).get("platform")
  +def create_enclosure(platform):
  +    """Create an enclosure based on the provided platform string.
   
  +    Arguments:
  +        platform (str): platform name string
  +
  +    Returns:
  +        Enclosure object
  +    """
       if platform == "mycroft_mark_1":
  -        LOG.debug("Creating Mark I Enclosure")
  +        LOG.info("Creating Mark I Enclosure")
           from mycroft.client.enclosure.mark1 import EnclosureMark1
           enclosure = EnclosureMark1()
       elif platform == "mycroft_mark_2":
  -        LOG.debug("Creating Mark II Enclosure")
  +        LOG.info("Creating Mark II Enclosure")
           from mycroft.client.enclosure.mark2 import EnclosureMark2
           enclosure = EnclosureMark2()
       else:
  -        LOG.debug("Creating generic enclosure, platform='{}'".format(platform))
  +        LOG.info("Creating generic enclosure, platform='{}'".format(platform))
   
           # TODO: Mechanism to load from elsewhere.  E.g. read a script path from
           # the mycroft.conf, then load/launch that script.
           from mycroft.client.enclosure.generic import EnclosureGeneric
           enclosure = EnclosureGeneric()
   
  +    return enclosure
  +
  +
  +def main():
  +    """Launch one of the available enclosure implementations.
  +
  +    This depends on the configured platform and can currently either be
  +    mycroft_mark_1 or mycroft_mark_2, if unconfigured a generic enclosure with
  +    only the GUI bus will be started.
  +    """
  +    # Read the system configuration
  +    system_config = LocalConf(SYSTEM_CONFIG)
  +    platform = system_config.get("enclosure", {}).get("platform")
  +
  +    enclosure = create_enclosure(platform)
       if enclosure:
           try:
               LOG.debug("Enclosure started!")
  -            enclosure.run()
  +            reset_sigint_handler()
  +            create_daemon(enclosure.run)
  +            wait_for_exit_signal()
           except Exception as e:
               print(e)
  -        finally:
  -            sys.exit()
       else:
  -        LOG.debug("No enclosure available for this hardware, running headless")
  +        LOG.info("No enclosure available for this hardware, running headless")
   
   
   if __name__ == "__main__":
  
verification_info: {"golden_diff": "diff --git a/mycroft/client/enclosure/__main__.py b/mycroft/client/enclosure/__main__.py\n--- a/mycroft/client/enclosure/__main__.py\n+++ b/mycroft/client/enclosure/__main__.py\n@@ -12,44 +12,67 @@\n # See the License for the specific language governing permissions and\n # limitations under the License.\n #\n-import sys\n+\"\"\"Entrypoint for enclosure service.\n \n+This provides any \"enclosure\" specific functionality, for example GUI or\n+control over the Mark-1 Faceplate.\n+\"\"\"\n+from mycroft.configuration import LocalConf, SYSTEM_CONFIG\n from mycroft.util.log import LOG\n-from mycroft.messagebus.client import MessageBusClient\n-from mycroft.configuration import Configuration, LocalConf, SYSTEM_CONFIG\n+from mycroft.util import (create_daemon, wait_for_exit_signal,\n+                          reset_sigint_handler)\n \n \n-def main():\n-    # Read the system configuration\n-    system_config = LocalConf(SYSTEM_CONFIG)\n-    platform = system_config.get(\"enclosure\", {}).get(\"platform\")\n+def create_enclosure(platform):\n+    \"\"\"Create an enclosure based on the provided platform string.\n \n+    Arguments:\n+        platform (str): platform name string\n+\n+    Returns:\n+        Enclosure object\n+    \"\"\"\n     if platform == \"mycroft_mark_1\":\n-        LOG.debug(\"Creating Mark I Enclosure\")\n+        LOG.info(\"Creating Mark I Enclosure\")\n         from mycroft.client.enclosure.mark1 import EnclosureMark1\n         enclosure = EnclosureMark1()\n     elif platform == \"mycroft_mark_2\":\n-        LOG.debug(\"Creating Mark II Enclosure\")\n+        LOG.info(\"Creating Mark II Enclosure\")\n         from mycroft.client.enclosure.mark2 import EnclosureMark2\n         enclosure = EnclosureMark2()\n     else:\n-        LOG.debug(\"Creating generic enclosure, platform='{}'\".format(platform))\n+        LOG.info(\"Creating generic enclosure, platform='{}'\".format(platform))\n \n         # TODO: Mechanism to load from elsewhere.  E.g. read a script path from\n         # the mycroft.conf, then load/launch that script.\n         from mycroft.client.enclosure.generic import EnclosureGeneric\n         enclosure = EnclosureGeneric()\n \n+    return enclosure\n+\n+\n+def main():\n+    \"\"\"Launch one of the available enclosure implementations.\n+\n+    This depends on the configured platform and can currently either be\n+    mycroft_mark_1 or mycroft_mark_2, if unconfigured a generic enclosure with\n+    only the GUI bus will be started.\n+    \"\"\"\n+    # Read the system configuration\n+    system_config = LocalConf(SYSTEM_CONFIG)\n+    platform = system_config.get(\"enclosure\", {}).get(\"platform\")\n+\n+    enclosure = create_enclosure(platform)\n     if enclosure:\n         try:\n             LOG.debug(\"Enclosure started!\")\n-            enclosure.run()\n+            reset_sigint_handler()\n+            create_daemon(enclosure.run)\n+            wait_for_exit_signal()\n         except Exception as e:\n             print(e)\n-        finally:\n-            sys.exit()\n     else:\n-        LOG.debug(\"No enclosure available for this hardware, running headless\")\n+        LOG.info(\"No enclosure available for this hardware, running headless\")\n \n \n if __name__ == \"__main__\":\n", "issue": "Skills and Enclosure background services fail to stop and are killed...\n## Be clear about the software, hardware and version you are running\r\n\r\nFor example: \r\n\r\nin CLI\r\n >> what version are you running                                                                                                                                               \r\n >> I am running mycroft-core version 20 oh 2, release 0                                                                                                                    \r\n >> You are on the latest version.\r\n\r\nOpensuse Leap 15.1\r\n## Try to provide steps that we can use to replicate the Issue\r\n\r\nFor example: \r\n\r\n1. CTRL+C in CLI\r\n2. Enter ./stop_mycroft.sh \r\n3. Skills and Enclosure services are eventually killed.\r\n4. Takes about 30 seconds total\r\n\r\n## Be as specific as possible about the expected condition, and the deviation from expected condition. \r\n\r\nuser@LinuxOS:~/mycroft-core> ./stop-mycroft.sh skills\r\nStopping skills (5579)...stopped.\r\nuser@LinuxOS:~/mycroft-core> ./stop-mycroft.sh enclosure\r\nStopping enclosure (5588)...failed to stop.\r\n  Killing enclosure (5588)...killed.\r\nuser@LinuxOS:~/mycroft-core> ./stop-mycroft.sh\r\nStopping all mycroft-core services\r\nStopping messagebus.service (5576)...stopped.\r\nStopping audio (5582)...stopped.\r\nStopping speech (5585)...stopped.\r\n...\r\nuser@LinuxOS:~/mycroft-core> ./stop-mycroft.sh\r\nStopping all mycroft-core services\r\nStopping messagebus.service (18995)...stopped.\r\nStopping skills (18998)...failed to stop.\r\n  Killing skills (18998)...killed.\r\nStopping audio (19001)...stopped.\r\nStopping speech (19004)...stopped.\r\nStopping enclosure (19007)...failed to stop.\r\n  Killing enclosure (19007)...killed.\r\nuser@LinuxOS:~/mycroft-core> \r\n\r\n\n", "before_files": [{"content": "# Copyright 2017 Mycroft AI Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\nimport sys\n\nfrom mycroft.util.log import LOG\nfrom mycroft.messagebus.client import MessageBusClient\nfrom mycroft.configuration import Configuration, LocalConf, SYSTEM_CONFIG\n\n\ndef main():\n    # Read the system configuration\n    system_config = LocalConf(SYSTEM_CONFIG)\n    platform = system_config.get(\"enclosure\", {}).get(\"platform\")\n\n    if platform == \"mycroft_mark_1\":\n        LOG.debug(\"Creating Mark I Enclosure\")\n        from mycroft.client.enclosure.mark1 import EnclosureMark1\n        enclosure = EnclosureMark1()\n    elif platform == \"mycroft_mark_2\":\n        LOG.debug(\"Creating Mark II Enclosure\")\n        from mycroft.client.enclosure.mark2 import EnclosureMark2\n        enclosure = EnclosureMark2()\n    else:\n        LOG.debug(\"Creating generic enclosure, platform='{}'\".format(platform))\n\n        # TODO: Mechanism to load from elsewhere.  E.g. read a script path from\n        # the mycroft.conf, then load/launch that script.\n        from mycroft.client.enclosure.generic import EnclosureGeneric\n        enclosure = EnclosureGeneric()\n\n    if enclosure:\n        try:\n            LOG.debug(\"Enclosure started!\")\n            enclosure.run()\n        except Exception as e:\n            print(e)\n        finally:\n            sys.exit()\n    else:\n        LOG.debug(\"No enclosure available for this hardware, running headless\")\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "mycroft/client/enclosure/__main__.py"}], "after_files": [{"content": "# Copyright 2017 Mycroft AI Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n#\n\"\"\"Entrypoint for enclosure service.\n\nThis provides any \"enclosure\" specific functionality, for example GUI or\ncontrol over the Mark-1 Faceplate.\n\"\"\"\nfrom mycroft.configuration import LocalConf, SYSTEM_CONFIG\nfrom mycroft.util.log import LOG\nfrom mycroft.util import (create_daemon, wait_for_exit_signal,\n                          reset_sigint_handler)\n\n\ndef create_enclosure(platform):\n    \"\"\"Create an enclosure based on the provided platform string.\n\n    Arguments:\n        platform (str): platform name string\n\n    Returns:\n        Enclosure object\n    \"\"\"\n    if platform == \"mycroft_mark_1\":\n        LOG.info(\"Creating Mark I Enclosure\")\n        from mycroft.client.enclosure.mark1 import EnclosureMark1\n        enclosure = EnclosureMark1()\n    elif platform == \"mycroft_mark_2\":\n        LOG.info(\"Creating Mark II Enclosure\")\n        from mycroft.client.enclosure.mark2 import EnclosureMark2\n        enclosure = EnclosureMark2()\n    else:\n        LOG.info(\"Creating generic enclosure, platform='{}'\".format(platform))\n\n        # TODO: Mechanism to load from elsewhere.  E.g. read a script path from\n        # the mycroft.conf, then load/launch that script.\n        from mycroft.client.enclosure.generic import EnclosureGeneric\n        enclosure = EnclosureGeneric()\n\n    return enclosure\n\n\ndef main():\n    \"\"\"Launch one of the available enclosure implementations.\n\n    This depends on the configured platform and can currently either be\n    mycroft_mark_1 or mycroft_mark_2, if unconfigured a generic enclosure with\n    only the GUI bus will be started.\n    \"\"\"\n    # Read the system configuration\n    system_config = LocalConf(SYSTEM_CONFIG)\n    platform = system_config.get(\"enclosure\", {}).get(\"platform\")\n\n    enclosure = create_enclosure(platform)\n    if enclosure:\n        try:\n            LOG.debug(\"Enclosure started!\")\n            reset_sigint_handler()\n            create_daemon(enclosure.run)\n            wait_for_exit_signal()\n        except Exception as e:\n            print(e)\n    else:\n        LOG.info(\"No enclosure available for this hardware, running headless\")\n\n\nif __name__ == \"__main__\":\n    main()\n", "path": "mycroft/client/enclosure/__main__.py"}]}