Skip to content

Instantly share code, notes, and snippets.

@PandaWhoCodes
Created January 4, 2023 08:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save PandaWhoCodes/95866217caa65a30f1629903449dc53d to your computer and use it in GitHub Desktop.
Save PandaWhoCodes/95866217caa65a30f1629903449dc53d to your computer and use it in GitHub Desktop.
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