Sobes.tech
Junior — Middle

Применяли ли вы модуль threading для организации параллельных потоков в Python?

sobes.tech AI

Answer from AI

Yes, the threading module in Python is used for creating and managing threads, which allows multiple tasks to run concurrently within a single process. For example, you can create a thread to execute a function that performs a long operation without blocking the main thread:

import threading
import time

def worker():
    print('Thread started')
    time.sleep(2)
    print('Thread finished')

thread = threading.Thread(target=worker)
thread.start()
print('Main thread continues to work')
thread.join()

This example shows how to run a function in a separate thread, allowing the main program to continue working in parallel.