I have a Tornado web server running several web services. I need one of the operations in Service A to call an operation on Service B. I'm using Suds to make this call to Service B. At the moment everything hangs unless I put the Suds call into a separate thread, but now I need to get data from that call (in Thread 1) back into the main thread so I can send it back to the original requesting web service (Service A). Some code:
if input.payment_info.issuer == 'Amex':
def t1():
url = 'http://localhost:8080/PaymentService?wsdl'
client = Client(url)
result = client.service.process_amex(payment_info.issuer, payment_info.number, payment_info.sort_code)
t = Thread(target=t1)
t.start()
if result == "Success":
return result #How can I access it to return it to the main service
Apologies if this is unclear, I know threading is a complex issue but I don't see any other options here as the code hangs without it.
Edit: To be clear, I'm not using suds to call Service A. The only instance of suds is being used to call Service B.
I've also tried using a Queue as per Alex Martelli's post here (http://stackoverflow.com/a/2846697/559504) but it hangs again.
if input.payment_info.issuer == 'Amex':
def t1(q):
url = 'http://localhost:8080/PaymentService?wsdl'
client = Client(url)
result = client.service.process_amex(payment_info.issuer, payment_info.number, payment_info.sort_code)
q.put(result)
q = Queue.Queue()
t = Thread(target=t1, args=(q))
t.daemon = True
t.start()
result = q.get()
if result == "Success":
return "Success"