Probably just need to change `if packet` to `if not packet: return`.