4-2 Multithreading practice questions

Three practice questions

1. Implement concurrent socket communication based on multithreading

2. Write a simple text processing tool with three tasks, one to receive user input, one to format user input into uppercase, and one to store the formatted result in a file

 

two exercises

Consider what might be the result of the execution of the following code? Why?

from threading import Thread
import time

def foo():
    print(123)
    time.sleep(1)
    print("end123")

def bar():
    print(456)
    time.sleep(3)
    print("end456")

if __name__ == '__main__':
    t1=Thread(target=foo)
    t2=Thread(target=bar)

    t1.daemon=True
    t1.start()
    t2.start()
    print("main-------")



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324921407&siteId=291194637