THREADING

Tags:

Threading is something in Python that can allow you to be very intricate and use multiple a routes of code. These routes are usually connected by the same process but revolve around the same general idea. Threading in python can be used best in my to multitask. Threading could also be used in real life, for example in the kitchen. You could be working on different little things that are all to do with one meal.

an example of the start command of threading is:

import logging
import threading
import time

def thread_function(name):
    logging.info("Thread %s: starting", name)
    time.sleep(2)
    logging.info("Thread %s: finishing", name)

if __name__ == "__main__":
    format = "%(asctime)s: %(message)s"
    logging.basicConfig(format=format, level=logging.INFO,
                        datefmt="%H:%M:%S")

    logging.info("Main    : before creating thread")
    x = threading.Thread(target=thread_function, args=(1,))
    logging.info("Main    : before running thread")
    x.start()
    logging.info("Main    : wait for the thread to finish")
    # x.join()
    logging.info("Main    : all done") 

Categories

No Responses

Leave a Reply

Your email address will not be published. Required fields are marked *