Skip to main content
added multiple thread logic.
Source Link
fth
  • 2.6k
  • 3
  • 31
  • 44

You should pass a Queue instance as a parameter then you should .put() your return object into the queue. You can gather the return value via queue.get() whatever object you put.

Sample:

queue = Queue.Queue() thread_ = threading.Thread( target=target_method, name="Thread1", args=[params, queue], ) thread_.start() thread_.join() queue.get() def target_method(self, params, queue): """ Some operations right here """ your_return = "Whatever your object is" queue.put(your_return) 

Use for multiple threads:

#Start all threads in thread pool for thread in pool: thread.start() response = queue.get() thread_results.append(response) #Kill all threads for thread in pool: thread.join() 

I use this implementation and it works great for me. I wish you do so.

You should pass a Queue instance as a parameter then you should .put() your return object into the queue. You can gather the return value via queue.get() whatever object you put.

Sample:

queue = Queue.Queue() thread_ = threading.Thread( target=target_method, name="Thread1", args=[params, queue], ) thread_.start() thread_.join() queue.get() def target_method(self, params, queue): """ Some operations right here """ your_return = "Whatever your object is" queue.put(your_return) 

I use this implementation and it works great for me. I wish you do so.

You should pass a Queue instance as a parameter then you should .put() your return object into the queue. You can gather the return value via queue.get() whatever object you put.

Sample:

queue = Queue.Queue() thread_ = threading.Thread( target=target_method, name="Thread1", args=[params, queue], ) thread_.start() thread_.join() queue.get() def target_method(self, params, queue): """ Some operations right here """ your_return = "Whatever your object is" queue.put(your_return) 

Use for multiple threads:

#Start all threads in thread pool for thread in pool: thread.start() response = queue.get() thread_results.append(response) #Kill all threads for thread in pool: thread.join() 

I use this implementation and it works great for me. I wish you do so.

added 21 characters in body
Source Link
fth
  • 2.6k
  • 3
  • 31
  • 44

You should pass a Queue instance as a parameter then you should .put() your return object into the queue. You can gather the return value via queue.get() whatever object you put.

Sample:

queue = Queue.Queue() thread_ = threading.Thread( target=target_method, name="Thread1", args=[params, queue], ) thread_.start() thread_.join() queue.get() def target_method(self, params, queue): """ Some operations right here """ your_return = "Whatever your object is" queue.put(your_return) 

I use this implementation and it works great for me. I wish you do so.

You should pass a Queue instance as a parameter then you should .put() your return object into the queue. You can gather the return value via queue.get() whatever object you put.

Sample:

queue = Queue.Queue() thread_ = threading.Thread( target=target_method, name="Thread1", args=[params, queue], ) thread_.join() queue.get() def target_method(self, params, queue): """ Some operations right here """ your_return = "Whatever your object is" queue.put(your_return) 

I use this implementation and it works great for me. I wish you do so.

You should pass a Queue instance as a parameter then you should .put() your return object into the queue. You can gather the return value via queue.get() whatever object you put.

Sample:

queue = Queue.Queue() thread_ = threading.Thread( target=target_method, name="Thread1", args=[params, queue], ) thread_.start() thread_.join() queue.get() def target_method(self, params, queue): """ Some operations right here """ your_return = "Whatever your object is" queue.put(your_return) 

I use this implementation and it works great for me. I wish you do so.

Source Link
fth
  • 2.6k
  • 3
  • 31
  • 44

You should pass a Queue instance as a parameter then you should .put() your return object into the queue. You can gather the return value via queue.get() whatever object you put.

Sample:

queue = Queue.Queue() thread_ = threading.Thread( target=target_method, name="Thread1", args=[params, queue], ) thread_.join() queue.get() def target_method(self, params, queue): """ Some operations right here """ your_return = "Whatever your object is" queue.put(your_return) 

I use this implementation and it works great for me. I wish you do so.