Switch to context manager

This commit is contained in:
croneter 2021-07-23 10:29:34 +02:00
parent 07a69a8fa5
commit 143c6271aa

View file

@ -151,16 +151,13 @@ class ProcessingQueue(queue.Queue, object):
Once the get()-method returns None, you've received the sentinel and Once the get()-method returns None, you've received the sentinel and
you've thus exhausted the queue you've thus exhausted the queue
""" """
self.not_full.acquire() with self.not_full:
try:
section.number_of_items = 1 section.number_of_items = 1
self._add_section(section) self._add_section(section)
# Add the actual sentinel to the queue we just added # Add the actual sentinel to the queue we just added
self._queues[-1]._put((None, None)) self._queues[-1]._put((None, None))
self.unfinished_tasks += 1 self.unfinished_tasks += 1
self.not_empty.notify() self.not_empty.notify()
finally:
self.not_full.release()
def add_section(self, section): def add_section(self, section):
""" """
@ -170,11 +167,8 @@ class ProcessingQueue(queue.Queue, object):
Be sure to set section.number_of_items correctly as it will signal Be sure to set section.number_of_items correctly as it will signal
when processing is completely done for a specific section! when processing is completely done for a specific section!
""" """
self.mutex.acquire() with self.mutex:
try:
self._add_section(section) self._add_section(section)
finally:
self.mutex.release()
def _add_section(self, section): def _add_section(self, section):
self._sections.append(section) self._sections.append(section)