python - Map not returning anything -


i have following code:

def upload_to_s3(filepath, unique_id):     #     print s3_url # <-- confirming `s3_url` variable not none     return s3_url   threads = [] num, list_of_paths in enumerate(chunked_paths_as_list):     filepath in list_of_paths:         t = threading.thread(target=upload_to_s3, args=(filepath, self.unique_id))         t.start()         threads.append(t) results = map(lambda t: t.join(), threads) print results 

unfortunately, returning none every item:

[none, none, none, none, none, none, none, none, none, none, none, none, none, none, none, none, none, none, none, none, none, none, none] >>>>> time: 13.9884989262 

what need return statement in above map ?

t.join() always returns none. that's because return value of thread target ignored.

you'll have collect results other means, queue object:

from queue import queue  results = queue()  def upload_to_s3(filepath, unique_id):     #     print s3_url # <-- confirming `s3_url` variable not none     results.put(s3_url)   threads = [] num, list_of_paths in enumerate(chunked_paths_as_list):     filepath in list_of_paths:         t = threading.thread(target=upload_to_s3, args=(filepath, self.unique_id))         t.start()         threads.append(t) t in threads:     t.join()  while not results.empty():     print results.get() 

alternatively, use multiprocessing.dummy module multiprocessing.pool behaviour threads, can want; collect return values async function calls.


Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -