Revencu
@Revencu

Как работает параметр timeout в join() threads python?

for i in range(0,50):
   t=threading.Thread(target=runcode, args=(i,))
   t.daemon=True
   t.start()
   t.join(60.0)

Что решают эти 60 секунд у join() когда:
1. поток завершается раньше 60 секунд?
2. поток завершается позже 60 секунд?

Как продолжить выполнение кода после цикла потоков если какой-то поток "застрял" больше часа (в этом случае его результат не важен)?
  • Вопрос задан
  • 1626 просмотров
Пригласить эксперта
Ответы на вопрос 1
join([timeout])

Wait until the thread terminates. This blocks the calling thread until the thread whose join() method is called terminates – either normally or through an unhandled exception – or until the optional timeout occurs.

When the timeout argument is present and not None, it should be a floating point number specifying a timeout for the operation in seconds (or fractions thereof). As join() always returns None, you must call isAlive() after join() to decide whether a timeout happened – if the thread is still alive, the join() call timed out.

When the timeout argument is not present or None, the operation will block until the thread terminates.

A thread can be join()ed many times.

join() raises a RuntimeError if an attempt is made to join the current thread as that would cause a deadlock. It is also an error to join() a thread before it has been started and attempts to do so raises the same exception.

©
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы