avoid using print() function
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 68/100
Direzione di ricerca
Apri brping/device.py e ispeziona connect_serial(), comprese le due chiamate a print e il percorso di gestione delle eccezioni esistente. Esegui i casi di dispositivo mancante e di apertura riuscita per confermare che il primo sollevi un’eccezione come descritto e che il secondo non scriva più su stdout.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
This is just a copy of connect_serial() method from brping/device.py (ver 0.1.5)
def connect_serial(self, device_name: str, baudrate: int =115200):
if device_name is None:
print("Device name is required")
return
try:
print("Opening %s at %d bps" % (device_name, baudrate))
## Serial object for device communication
# write_timeout fixes it getting stuck forever atempting to write to
# /dev/ttyAMA0 on Raspberry Pis, this raises an exception instead.
self.iodev = serial.Serial(device_name, baudrate, write_timeout=1.0)
self.iodev.send_break()
time.sleep(0.001)
self.iodev.write("U".encode("ascii"))
except Exception as exception:
raise Exception("Failed to open the given serial port: {0}".format(exception))
The request here is:
Kindly avoid using the print function in a library like this. If the device name is required, it should be handled as an exception, not with a print and return:
raise ValueError("Device name is required")
And the next print is indeed a logging:
logger.info("Opening %s at %d bps", device_name, baudrate)
I've had to use workarounds to prevent these prints from being sent to my app's stdout:
def brping_muted_print(*args, **kw):
if len(args) == 1:
args = args[0]
log('brping: %s', args)
# brping module uses raw print statements for logging
# with this trick, we turn them into proper logs
brping.device.print = brping_muted_print
Thanks
- Lingua principale
- Python
- Stelle
- 60
- Fork
- 39
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di bluerobotics/ping-python
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 62/100
bluerobotics/ping-python#74 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 25/100
bluerobotics/ping-python#171 ·
-
set sound speed Aperta
bluerobotics/ping-python#169 · 2 commenti · 1 assegnatario ·
-
Code after return Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 48/100
bluerobotics/ping-python#167 ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 32/100
bluerobotics/ping-python#159 ·
Tutte le issue di bluerobotics/ping-python
Issue simili
-
sponsored
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
Diaoul/subliminal#1382 ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
-
triage/confirmed
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
agentscope-ai/agentscope#2775 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 84/100