0

Say I have the following pandas df:

col_1  |   col_2  |   server_one_response   |  server_two_response
  5          2 
  2          3
  2          8
  9          8
  10         9

How could I apply the 2 functions from below on my df on 2 different threads (not processes) to return data from 2 different servers:

def get_server_one_result(a, b):
   'get some interestig data from the server'
   return response

def get_server_two_result(a, b):
   'get some interestig data from another server'
   return response

The point is that while the first function is busy waiting for a server response and calculation, the other function will retrieve data from another server.

callmeGuy
  • 944
  • 2
  • 11
  • 28
  • 2
    And that post is a duplicate of another duplicate... It's impossible to run things in parallel in Python unless you spawn multiple processes, but since you only want python to not wait until server responds, you should just use something like asyncio to asynchronously get data, using threads will do literally nothing except next thread will be used when first one blocks. If you want to do that with threading, then why don't you just loop up how to multithread with Python? There's enough examples on internet to get it working without any problems. – Purple Ice Oct 23 '18 at 11:45
  • how is this a duplicate? I am asking how to apply 2 functions on 2 threads on a pandas df. Similar in threading, yes, but different question – callmeGuy Oct 23 '18 at 11:48
  • it is a duplicate because running functions parallel in python is not a pandas question, it is a python question. – user3471881 Oct 23 '18 at 11:51
  • i dont think so, when you read and write data in paralel on the same df it's a different story, that's why I mentioned pandas – callmeGuy Oct 23 '18 at 11:57
  • Don't write to the df in parallel: write the returned output from the processes into your dataframe in the main thread. And send the two threads copies of the (reduced, i.e., only essential columns) dataframe. – 9769953 Oct 23 '18 at 12:04

0 Answers0