Unerwartetes Verhalten beim Iterieren über zwei SchleifenPython

Python-Programme
Anonymous
 Unerwartetes Verhalten beim Iterieren über zwei Schleifen

Post by Anonymous »

Hier sind die Python -Code -Snippets für update_totps_loop und update_remaining_loop: < /pbr />

Code: Select all

def update_totps_loop(self):
for i, (item_id, key, _) in enumerate(self.totp_rows):
new_val = pyotp.TOTP(key).now()
self.totp_tree.set(item_id, "code", new_val)
# self.after(1000, self.update_totps_loop)
vTimeTk_ns = time.time_ns()
vUpdateTOTPS30s = (vTimeTk_ns / 30000000000)
if vUpdateTOTPS30s - int(vUpdateTOTPS30s) > 0.5:
vUpdateTOTPS30s += 1 + vUpdateTOTPS30s - int(vUpdateTOTPS30s)
vNextTOTPUpdate = 30 - ((vUpdateTOTPS30s - int(vUpdateTOTPS30s)) * 30)
self.vInt_RemainingSecs = int(vNextTOTPUpdate + 1)
print(str(time.ctime()) + ",TOTP," + str(vTimeTk_ns) + "," + str(vUpdateTOTPS30s) + "," + str(int(vUpdateTOTPS30s))  + "," + str((vUpdateTOTPS30s - int(vUpdateTOTPS30s)) * 30) + "," + str(vNextTOTPUpdate) + "," + str(self.vInt_RemainingSecs))
self.update_remaining_loop()
self.after(int((vNextTOTPUpdate * 1000) + 1), self.update_totps_loop)

def update_remaining_loop(self):
self.remaining_label.config(text=str(self.vInt_RemainingSecs))

print(str(time.ctime(time.time())) + ",BEFORE,,,,," + str((self.vInt_RemainingSecs)))
self.vInt_RemainingSecs -= 1
print(str(time.ctime(time.time())) + ",AFTER,,,,," + str((self.vInt_RemainingSecs)))

if self.vInt_RemainingSecs > 0:
self.after(1000, self.update_remaining_loop)
< /code>
Und hier ist die Terminalausgabe: < /p>
Thu Jul 24 22:19:48 2025,TOTP,1753375788873276457,58445861.25821844,58445861,7.746553122997284,22.253446877002716,23
Thu Jul 24 22:19:48 2025,BEFORE,,,,,23
Thu Jul 24 22:19:48 2025,AFTER,,,,,22
Thu Jul 24 22:19:49 2025,BEFORE,,,,,0.1
Thu Jul 24 22:19:49 2025,AFTER,,,,,-0.9
Thu Jul 24 22:20:11 2025,TOTP,1753375811128115913,58445860.3709372,58445860,11.128115952014923,18.871884047985077,19
Thu Jul 24 22:20:11 2025,BEFORE,,,,,19
Thu Jul 24 22:20:11 2025,AFTER,,,,,18
Thu Jul 24 22:20:12 2025,BEFORE,,,,,18
Thu Jul 24 22:20:12 2025,AFTER,,,,,17
Thu Jul 24 22:20:13 2025,BEFORE,,,,,17
Thu Jul 24 22:20:13 2025,AFTER,,,,,16
Thu Jul 24 22:20:14 2025,BEFORE,,,,,16
Thu Jul 24 22:20:14 2025,AFTER,,,,,15
Thu Jul 24 22:20:15 2025,BEFORE,,,,,15
.
.
.
< /code>
update_remaining_loop
wird von update_totps_loop aufgerufen, nachdem er self.vint_remainingSecs auf eine Nummer zwischen 1 und 30 in update_totps_loop . /> Frage lautet: Warum ist self.vint_remainingSecs in der 2. Iteration von update_remaining_loop auf -0.1 festgelegt>

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post