Edoruin commited on
Commit
3601b92
·
1 Parent(s): 0244193

40ERROR WITH Ai MODEL CLASSROOMMAKER ENDPOINT

Browse files
Files changed (2) hide show
  1. app/main.py +30 -9
  2. app/templates/prestamos.html +1 -1
app/main.py CHANGED
@@ -2,6 +2,7 @@ import eventlet
2
  eventlet.monkey_patch() # Parchea librerías estándar para compatibilidad con eventlet (necesario para Socket.IO)
3
 
4
  import os
 
5
  import json
6
  import uuid
7
  import threading
@@ -472,15 +473,35 @@ if bot:
472
  print(f"Command Error: {e}")
473
 
474
  def start_bot_thread():
475
- if bot:
476
- time.sleep(5)
477
- try: bot.delete_webhook()
478
- except: pass
479
- while True:
480
- try:
481
- bot.infinity_polling(timeout=20, long_polling_timeout=10)
482
- except Exception as e:
483
- time.sleep(30)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
484
 
485
  if bot:
486
  threading.Thread(target=start_bot_thread, daemon=True).start()
 
2
  eventlet.monkey_patch() # Parchea librerías estándar para compatibilidad con eventlet (necesario para Socket.IO)
3
 
4
  import os
5
+ import fcntl
6
  import json
7
  import uuid
8
  import threading
 
473
  print(f"Command Error: {e}")
474
 
475
  def start_bot_thread():
476
+ if not bot:
477
+ return
478
+
479
+ # Usar un lock de archivo para prevenir múltiples instancias en Gunicorn workers o Flask reloader
480
+ try:
481
+ # Abrimos el archivo en modo escritura y pedimos un lock exclusivo no bloqueante
482
+ lock_file_path = "/tmp/tg_bot.lock"
483
+ # Mantenemos la referencia al archivo abierta para que el lock sea efectivo mientras el hilo viva
484
+ # Nota: En Python, si el objeto file se cierra, el lock se libera.
485
+ # Por eso lo hacemos global o lo mantenemos en el scope del bucle.
486
+ global _bot_lock_file
487
+ _bot_lock_file = open(lock_file_path, "w")
488
+ fcntl.flock(_bot_lock_file, fcntl.LOCK_EX | fcntl.LOCK_NB)
489
+ except (IOError, OSError):
490
+ # Si no podemos obtener el lock, es que otra instancia ya lo tiene
491
+ print("[BOT] Otra instancia detectada. No se iniciará el bot en este hilo.")
492
+ return
493
+
494
+ time.sleep(5)
495
+ try: bot.delete_webhook()
496
+ except: pass
497
+
498
+ print("[BOT] Iniciando polling...")
499
+ while True:
500
+ try:
501
+ bot.infinity_polling(timeout=20, long_polling_timeout=10)
502
+ except Exception as e:
503
+ print(f"[BOT ERROR] {e}")
504
+ time.sleep(30)
505
 
506
  if bot:
507
  threading.Thread(target=start_bot_thread, daemon=True).start()
app/templates/prestamos.html CHANGED
@@ -52,7 +52,7 @@
52
  <label>Categoría</label>
53
  <select name="categoria[]">
54
  <option value="Herramientas">Herramientas</option>
55
- <option value="Dispositivos Eléctricos">Dispositivos Eléctricos</option>
56
  </select>
57
  </div>
58
  <div class="form-group">
 
52
  <label>Categoría</label>
53
  <select name="categoria[]">
54
  <option value="Herramientas">Herramientas</option>
55
+ <option value="Dispositivos Eléctricos">Dispositivos</option>
56
  </select>
57
  </div>
58
  <div class="form-group">