Docsity

Quiz 5 for Scripting Languages | ECS 145, Quizzes of Computer Science

Toggle sidebar
bg1
ECS145 Scripting Languages - Spring 2005 Name:
Quiz 5
1. (2pts) How do you start the debugger within your program?
import pdb
pdb.set_trace()
2. (2pts) Are compute-bound programs parallelizable in Python?
No
3. (4pts) Change the code snippet below so that condition variables are no longer used.
You may still use other concurrency mechanisms like Locks and Events.
lock = threading.Lock()
evt = threading.Event()
# Consume one item
lock.acquire()
while not an_item_is_available():
evt.wait()
get_an_available_item()
lock.release()
# Produce one item
lock.acquire()
make_an_item_available()
evt.set()
lock.release()

Partial preview of the text

Download Quiz 5 for Scripting Languages | ECS 145 and more Quizzes Computer Science in PDF only on Docsity!

ECS145 Scripting Languages - Spring 2005 Name:

Quiz 5

  1. (2pts) How do you start the debugger within your program?

import pdb

pdb.set_trace()

  1. (2pts) Are compute-bound programs parallelizable in Python?

No

  1. (4pts) Change the code snippet below so that condition variables are no longer used. You may still use other concurrency mechanisms like Locks and Events.

lock = threading.Lock() evt = threading.Event()

Consume one item

lock.acquire() while not an_item_is_available(): evt.wait() get_an_available_item() lock.release()

Produce one item

lock.acquire() make_an_item_available() evt.set() lock.release()