“Python Threading Return Valor” Respostas de código

Python Thread com valores de retorno?

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)
Exuberant Earthworm

Python Threading Return Valor

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)
Uninterested Unicorn

Respostas semelhantes a “Python Threading Return Valor”

Perguntas semelhantes a “Python Threading Return Valor”

Mais respostas relacionadas para “Python Threading Return Valor” em Python

Procure respostas de código populares por idioma

Procurar outros idiomas de código