Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python thread with return values?

import threading
import queue

my_queue = queue.Queue()

def storeInQueue(f):
  def wrapper(*args):
    my_queue.put(f(*args))
  return wrapper


@storeInQueue
def get_name(full_name):
   return full_name, full_name



t = threading.Thread(target=get_name, args = ("foo", ))
t.start()

my_data = my_queue.get()
print(my_data)
Comment

python threading return value

import concurrent.futures

def foo(bar):
    print('hello {}'.format(bar))
    return 'foo'

with concurrent.futures.ThreadPoolExecutor() as executor:
    future = executor.submit(foo, 'world!')
    return_value = future.result()
    print(return_value)
Comment

PREVIOUS NEXT
Code Example
Python :: count occurrence in array python 
Python :: python combine two lists into matrix 
Python :: transition from python 2 to 3 terminal 
Python :: php datatables serverside 
Python :: python fractions 
Python :: python how to turn a word into a list 
Python :: convert to datetime object 
Python :: append to list py 
Python :: pandas melt() function, change the DataFrame format from wide to long 
Python :: replace list 
Python :: pandas dataframe.to_dict 
Python :: map example in python 
Python :: planets list 
Python :: python nominatim get latitude from address 
Python :: learn python the hard way 
Python :: python strptime() 
Python :: python str contains word 
Python :: ffill dataframe python 
Python :: how to call a random function in python 
Python :: change index to dataframe pandas 
Python :: python json random number generator 
Python :: python game 
Python :: manage.py startapp not working in django 
Python :: concat string columns in pandas 
Python :: extract text from pdf python 
Python :: how to get a int from string python 
Python :: Python Tkinter Text Widget Syntax 
Python :: creating an entry widget for input in tkinter 
Python :: how to append panda columns using loop 
Python :: python define class 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =