Answer to Question #226636 in Python for Dion Martins

Question #226636
Edit, Debug and Run the given Python script files
"""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-17T12:51:53-0400
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()))

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