Answer to Question #222464 in Python for Dion Martins

Question #222464
1. Debug(find and correct errors) and run the Python script file Lab X,
2. Analyze the output and interpret what the script is about or does[reading comments may help]
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):

"""In the preceding code,a function myThread is defined. Within this function,
we utilize the threading.currentThread().getName()
in order to retrieve the current thread’s moniker, a
nd print this out both when we start our thread’s execution, and when it ends.
We then go on to start a for loop, and create four thread objects that take in
the name parameter, which we define as “Thread-” + str(i), as well as
the myThread function as the target of that thread’s execution.
We then, finally, go on to print out all the active threads currently running.
"""
1
Expert's answer
2021-08-02T07:16:08-0400
#import threading module
import threading
#import time module
import time


#define myThread function taking i as an argument
def myThread(i):
    print("Thread {} starting".format(threading.currentThread().getName()))
    
    time.sleep(10)
    
    print("Thread {} ending".format(threading.currentThread().getName()))
    
    for i in range(4):
        pass

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