IRNAS / ppk2-api-python

Power Profiling Kit 2 unofficial python api.
http://irnas.eu
GNU General Public License v2.0
145 stars 37 forks source link

Questions about try/except in many functions #35

Open Stefanhg opened 1 year ago

Stefanhg commented 1 year ago

Hello, I have been doing some debugging of my own version of this package and found some problem with write timeout. In your package you have many try/except's wrapped around the functions. How come you have done this?

wlgrd commented 4 months ago

Please provide some more specific examples as to what you are looking at. In Python, try/except is used for exception handling, and not all exceptions has to be so severe that the program needs to crash, thus it is handled more gracefully.

For instance, the get method of queue.Queue will raise an exception if it is empty. So it's better dealt with like this

        while True:
            try:
                self._buffer_q.get(block=False)
            except queue.Empty:
                break

so the program isn't crashing just because the buffer doesn't have any data yet.