4

I have written a Python function that uses multithreading.

def image(link_ID):
    tid1 = Thread(target=displayImage, args=(link_ID,))
    tid2 = Thread(target=publishIAmFree)
    tid1.start()
    tid2.start()

Function displayImage() simply puts up the image and the function publishIAmFree() publishes data to the broker and returns a FLAG value.

How will I get the return value from the publishIAmFree() function, while in the thread?

Vineeth Sai
  • 3,389
  • 7
  • 23
  • 34
Adam_zampa
  • 55
  • 4

1 Answers1

1

You could try using the ThreadPool class

from multiprocessing.pool import ThreadPool
threadp = ThreadPool(processes=1)

res = threadp.apply_async(publishIAmFree, ()) # () has the arguments for function

return_val = res.get()
print return_val
Vineeth Sai
  • 3,389
  • 7
  • 23
  • 34
  • 1
    tid1 = Thread(target=displayImage, args=(link_ID,)) will this be the same and be used along with res = threadp.apply_async(publishIAmFree, ()) – Adam_zampa Sep 20 '18 at 12:07