Answer to Question #226641 in Python for Dion Martins

Question #226641
1. Edit, Debug and Run the given Python script files: TP1.py
2. The Evaluator will allocate marks based on the correct output results

"""In distributed systems, it is a good idea to segregate threads into groups
if they are performing different tasks. Say, for instance, you have an
application that both listens for incoming stock price changes
and also tries to predict where that price will go. You could, for instance,
have two different thread groups here: one group listening for the changes
and the other performing the necessary calculations.
"""
import threading
import time
def myThread():
print("Thread {%} starting".format(threading.currentThread().getName()))
time.sleep(10)
print("Thread {} ending".format(threading.currentThread().getName()))
for i in range(4):
threadName = "Thread-" + str(i)
thread = threading.Thread(name=threadName, target=myThread)
thread.start()
print("{#}".format(threading.enumerate()))
1
Expert's answer
2021-08-16T14:49:37-0400
import threading

mport time

def myThread():
    print("\nThread: {} starting".format(threading.currentThread().getName()))
    time.sleep(5)
    print("\nThread: {} ending".format(threading.currentThread().getName()))
    for i in range(4):
        threadName = "Thread-" + str(i)
        thread = threading.Thread(name=threadName, target=myThread)
        thread.start()
#        print("\n{}".format(threading.enumerate()))


myThread()

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS