MCQs > IT & Programming > Python > Output of following code? import threading k = 10 x = 0 m = threading.Lock() def foo(): global x for i in xrange(k): with m: x += 1 def bar(): global x for i in xrange(k): with m: x -= 1 t1 = threading.Thread(target=foo) t2 = threading.Thread(target=bar) t1.start() t2.start() t1.join() t2.join() print x

Python MCQs

What will be the output of following code? import threading k = 10 x = 0 m = threading.Lock() def foo(): global x for i in xrange(k): with m: x += 1 def bar(): global x for i in xrange(k): with m: x -= 1 t1 = threading.Thread(target=foo) t2 = threading.Thread(target=bar) t1.start() t2.start() t1.join() t2.join() print x

Answer

Correct Answer: It will raise an exception.

Explanation:

Note: This Question is unanswered, help us to find answer for this one

Python Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it

search

Python Skill Assessment

Overall Skill Level-Poor

Your Skill Level: Poor

Retake Quizzes to improve it