0

I am using threading.Thread(target, *args, **k) from the Python threading library:

t = Thread(
            target=self.connect,
            args=(
                hostname,
                username,
                password,
                pre_name,
                config_data,
                action,
                post_name),
            kwargs=key_value
        )

When I call t.start() - it executes the function in the target, but if the values are wrong or the device is not available - the thread will throw an exception, and the system will hang.

I get the following traceback:

Exception in thread Thread-2:
  Traceback (most recent call last):
  File "C:\Python27\lib\threading.py", line 801, in __bootstrap_inner
    self.run()
  File "C:\Python27\lib\threading.py", line 754, in run
    self.__target(*self.__args, **self.__kwargs)

the connect function called in a particular thread is throwing an exception -which is not being identified by its parent thread.

How can the rest of my program know of this exception (so I can handle it)?

boardrider
  • 5,882
  • 7
  • 49
  • 86
  • You may want to read [help/on-topic], [ask] and [mcve], and re-word your question accordingly. – boardrider Jun 10 '17 at 10:19
  • Possible duplicate of [Catch a thread's exception in the caller thread in Python](https://stackoverflow.com/questions/2829329/catch-a-threads-exception-in-the-caller-thread-in-python) – zwer Jun 10 '17 at 11:20

0 Answers0