Write a thread-safe implementation of a producer-consumer queue for sensor data.
Implement the function below using a bounded FIFO queue protected by synchronization. Producers block when the queue is full, consumers block when it is empty, and operations with timeout=0 fail immediately. Closing the queue rejects new items but allows existing items to be consumed.
producer_consumer_queue(capacity, operations) receives a positive integer and operation strings such as put:temp, put:temp(timeout=0), get, get(timeout=0), and close. Return outputs from get operations and exception names from failed operations.
(timeout=0)def producer_consumer_queue(capacity, operations):