0

I am working on a simple application with GUI which connect to a server via SOAP and request some data, this data is returned in XML format

I was able to run in my application successfully but due to threading, GUI is freezes till the complete SOAP request is finished and returned its value

now I am trying to run my application into threading, I created a Thread which to first check and verify the SOAP connection if it is successful or not

Connection Verification

class WorkerThread(QThread):
    def __init__(self, parent=None):
        super(WorkerThread, self).__init__(parent)

    def run(self):
        self.session = Session()
        self.session.verify = False
        self.cucmurl = 'https://URL'
        self.session.auth = HTTPBasicAuth(user, pass)
        self.cache = SqliteCache(path='/tmp/sqlite.db', timeout=10)
        self.trself.clientansport = Transport(session=self.session, cache=self.cache)
        self.client = Client(wsdl, transport=self.transport, strict=False)

the above work fine to verify the connection, but I want to use the self.client later in my code in order to start initiating SOAP connection to severs

class MainAPP(QTabWidget, UI_File):
     def __init__(self, parent=None):

      def getinfor(self):
       output_2 = self.client.getinfor('')

the function getinfor should be able to use the self.client from the WorkerThread.

any idea how to accomplish this

three_pineapples
  • 11,579
  • 5
  • 38
  • 75
Moo
  • 27
  • 4

1 Answers1

1

You can emit the client through a signal from the worker thread and set it in the main window.

class WorkerThread(QThread):

    client_signal = pyqtSignal(object)

    def __init__(self, parent=None):
        super(WorkerThread, self).__init__(parent)

    def run(self):
        # code here
        self.client = Client(wsdl, transport=self.transport, strict=False)
        self.client_signal.emit(self.client)


class MainApp(QTabWidget, UI_File):

    def __init__(self):
        self.client = None

    def set_client(self, client):
        self.client = client

    def setup_thread(self):
        self.worker_thread = WorkerThread()
        self.worker_thread.client_signal.connect(self.set_client)
MalloyDelacroix
  • 2,193
  • 1
  • 13
  • 17
  • The success of this may depend on whether `Client` (or any objects within) cares about being used from a thread different to the thread it was constructed in. – three_pineapples Feb 27 '18 at 03:32