CroatianMeteorNetwork / RMS

RPi Meteor Station
https://globalmeteornetwork.org/
GNU General Public License v3.0
178 stars 50 forks source link

Convert worker_timeout to int for logging #187

Closed g7gpr closed 1 year ago

g7gpr commented 1 year ago

When running processing after capture, worker_timeout is generally not an integer, as it includes the capture duration. This change converts it to an int for logging.

dvida commented 1 year ago

What if it can't be converted to an integer, which seems to be causing the issue in the first place? It will crash the program.

g7gpr commented 1 year ago

Happy to write something safer if you can make a suggestion.

This is what I tested.

Current code - crash

>>> print("Int conversion {:d}".format(3.157))

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: Unknown format code 'd' for object of type 'float''

Option 1 wrap in int()

>>> print("Int conversion {:d}".format(int(3.157)))
Int conversion 3

Option 2 Get rid of format code

>>> print("Int conversion {}".format(3.157))
Int conversion 3.157

Option 3 Format to float

>>> print("To float {:.2f}".format(3.157))
To float 3.16
>>> 
g7gpr commented 1 year ago

So would you suggest putting it in a try: except: ?

dvida commented 1 year ago

Thanks! I might not be understanding the problem, but why don't we make the format float, and convert to float? If that is the type that gets passed in anyway.

g7gpr commented 1 year ago

I'll test that approach.

dvida commented 1 year ago

And just in case the timeout is integer, could you do float(worker_timeout) in the print? Thanks!