Wraps an instance of any other Output-like object to make its write function more thread safe.
| 249 | |
| 250 | |
| 251 | class QueueOutputWrapper(object): |
| 252 | """ |
| 253 | Wraps an instance of any other Output-like object to make its |
| 254 | write function more thread safe. |
| 255 | """ |
| 256 | |
| 257 | def __init__(self, oobject, oqueue): |
| 258 | self.__oobject = oobject |
| 259 | self.__owrite = oobject.write |
| 260 | self.queue = oqueue |
| 261 | self.id = str(self.__oobject) |
| 262 | |
| 263 | def true_write(self, *args, **kwargs): |
| 264 | "Calls the wrapped class's write function. Called from decode.py." |
| 265 | self.__owrite(*args, **kwargs) |
| 266 | |
| 267 | def write(self, *args, **kwargs): |
| 268 | """ |
| 269 | Adds a message to the queue indicating that this wrapper is ready to |
| 270 | run its write function |
| 271 | """ |
| 272 | self.queue.put((self.id, args, kwargs)) |
| 273 | |
| 274 | |
| 275 | ############################################################################### |