code: def get_connection(self):
          
          self.logger.debug(
              u"Connecting to WMI server "
              u"(host={host}, namespace={namespace}, provider={provider}, username={username}).".format(
                  host=self.host, namespace=self.namespace, provider=self.provider, username=self.username
              )
          )
  
          # Initialize COM for the current thread
          # WARNING: any python COM object (locator, connection, etc) created in a thread
          # shouldn't be used in other threads (can lead to memory/handle leaks if done
          # without a deep knowledge of COM's threading model). Because of this and given
          # that we run each query in its own thread, we don't cache connections
          additional_args = []
          pythoncom.CoInitialize()
  
          if self.provider != ProviderArchitecture.DEFAULT:
              context = Dispatch("WbemScripting.SWbemNamedValueSet")
              context.Add("__ProviderArchitecture", self.provider)
              additional_args = [None, "", 128, context]
  
          locator = Dispatch("WbemScripting.SWbemLocator")
          connection = locator.ConnectServer(self.host, self.namespace, self.username, self.password, *additional_args)
  
          return connection
docs: Create a new WMI connection