Octoprint-Filament-Reloaded icon indicating copy to clipboard operation
Octoprint-Filament-Reloaded copied to clipboard

Sleep bug (0 integer instead of seconds float)

Open cmin764 opened this issue 6 years ago • 1 comments

Under the code here:

   def sensor_callback(self, _):
        sleep(self.bounce/1000)

The self.bounce property returns an integer explicitly and in py2.7 the division will result into 0, which will not sleep at all. One possible solution would actually be:

   def sensor_callback(self, _):
        sleep(float(self.bounce) / 1000)

since we use the bounce in ms for the GPIO event (and we pass an integer there).

cmin764 avatar Feb 24 '19 17:02 cmin764

Also, I find this bug beneficial for the logic, because I don't feel like it should sleep there (therefore a sleep(0) will do nothing, which is the intended behaviour) as the event is already raised every bounce ms and the callback shouldn't block.

Finally, I think it's best to remove the sleeping entirely.

cmin764 avatar Feb 24 '19 17:02 cmin764