В настоящее время этот код печатает, < /p>
MainThread done at sec 1
MainThread done at sec 1
MainThread done at sec 2
MainThread done at sec 1
MainThread done at sec 0
MainThread done at sec 3
MainThread done at sec 2
MainThread done at sec 5
MainThread done at sec 4
< /code>
Мне нужно для печати < /p>
MainThread 1 done at sec 1
MainThread 3 done at sec 1
MainThread 2 done at sec 2
MainThread 3 done at sec 1
MainThread 1 done at sec 0
MainThread 2 done at sec 3
MainThread 2 done at sec 2
MainThread 3 done at sec 5
MainThread 1 done at sec 4
Как я могу это сделать, изменяя эту 1 строку кода.
print(threading.current_thread().name + ' done at sec ' + str(future.result()))
< /code>
Вот полный код < /p>
import concurrent.futures
import threading
import pdb
import time
import random
def Threads2(time_sleep):
time.sleep(time_sleep)
return time_sleep
all_sections = [random.randint(0, 5) for iii in range(10)]
test1 = []
with concurrent.futures.ThreadPoolExecutor(max_workers=3, thread_name_prefix="Ok") as executor:
working_threads = {executor.submit(Threads2, time_sleep): time_sleep for index, time_sleep in enumerate(all_sections)}
for future in concurrent.futures.as_completed(working_threads):
print(threading.current_thread().name + ' done at sec ' + str(future.result()))
Подробнее здесь: https://stackoverflow.com/questions/795 ... ead-number
Python 3 - concurrent.futures - Получить номер потока ⇐ Python
-
- Похожие темы
- Ответы
- Просмотры
- Последнее сообщение
-
-
Как распараллелить доступ к общему массиву в Python с помощью concurrent.futures?
Anonymous » » в форуме Python - 0 Ответы
- 41 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Проблемы со сбором всех тиковых данных с помощью Concurrent.futures в Python
Anonymous » » в форуме Python - 0 Ответы
- 25 Просмотры
-
Последнее сообщение Anonymous
-
-
-
Должен ли я использовать ВСЕ виртуальные ядра при использовании Python Concurrent Futures?
Anonymous » » в форуме Python - 0 Ответы
- 10 Просмотры
-
Последнее сообщение Anonymous
-
Мобильная версия