Skip to content Skip to sidebar Skip to footer

When I Run It Tells Me This : NameError: Name 'lock' Is Not Defined?

• Assume that you have an array (data=[]) containing 500,000 elements and that each element has been assigned a random value between 1 and 10 (random.randint(1,10)) . for i in

Solution 1:

You're missing

lock = threading.Lock()

And I think you should be importing threading instead of thread :

This module constructs higher-level threading interfaces on top of the lower level thread module.

Solution 2:

You haven't defied a variable lock. Here is how you can build a lock object called l in Python:

import threading
l = threading.Lock()

Adjusting this to the demands of your homework is left as an exercise.


Post a Comment for "When I Run It Tells Me This : NameError: Name 'lock' Is Not Defined?"