Created
January 4, 2023 08:29
-
-
Save PandaWhoCodes/95866217caa65a30f1629903449dc53d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import logging | |
import time | |
import threading | |
logger = logging.getLogger() | |
# Set up logging | |
logging.basicConfig( | |
level=logging.INFO, format="%(asctime)s %(message)s", datefmt="%Y-%m-%d %H:%M:%S" | |
) | |
def log_info(message,logger): | |
logger.info(message) | |
time.sleep(3) | |
logger.info(message) | |
threads = [] | |
for i in range(10): | |
t = threading.Thread( | |
target=log_info, args=("Hello from thread {}".format(i),logger) | |
) | |
threads.append(t) | |
# Start the threads | |
for t in threads: | |
t.start() | |
# Wait for the threads to complete | |
for t in threads: | |
t.join() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment