Pdb y trytond-console

Buenos días

Quisiera consultar si es posible usar pdb en trytond-console. Si introduzco un breakpoint() o import pdb; pdb.set_strace() me sale una excepción:

[3] > (19)()
(Pdb++)
Traceback (most recent call last):
File “”, line 19, in 
File “”, line 19, in 
File “/usr/lib/python3.7/bdb.py”, line 88, in trace_dispatch
return self.dispatch_line(frame)
File “/usr/lib/python3.7/bdb.py”, line 113, in dispatch_line
if self.quitting: raise BdbQuit
bdb.BdbQuit

Si necesito correr scripts en el servidor en combinación con el cron de Linux, suelo usar Proteus, me pregunto para que se debería usar o en qué casos trytond-console?

En caso de elegir trytond-console ¿ hay alguna manera de hacer debug que no sea usar prints?

Muchas gracias!

Luis

It is not currently possible.

We have this patch applied to allow that, but it would be great if it made it into core.

diff --git a/tryton/trytond/trytond/commandline.py b/tryton/trytond/trytond/commandline.py
index db8343848a..90d21c0977 100644
--- a/tryton/trytond/trytond/commandline.py
+++ b/tryton/trytond/trytond/commandline.py
@@ -161,6 +161,9 @@ def get_parser_console():
     parser.add_argument(
         "--lock-table", dest="lock_tables", nargs='+', default=[],
         metavar='TABLE', help="lock tables")
+    parser.add_argument("-f", "--file", dest="script", metavar='FILE',
+        default=[os.environ.get('TRYTOND_CONSOLE_FILE')],
+        help="Python script to execute")
     parser.epilog = "To store changes, `transaction.commit()` must be called."
     return parser
 
diff --git a/tryton/trytond/trytond/console.py b/tryton/trytond/trytond/console.py
index 8243f40644..f95e3a39d3 100644
--- a/tryton/trytond/trytond/console.py
+++ b/tryton/trytond/trytond/console.py
@@ -52,11 +52,15 @@ def run(options):
             'pool': pool,
             'transaction': transaction,
             }
-        if sys.stdin.isatty():
+        if sys.stdin.isatty() and not options.script:
             console = Console(local, histsize=options.histsize)
             banner = "Tryton %s, Python %s on %s" % (
                 __version__, sys.version, sys.platform)
             console.interact(banner=banner, exitmsg='')
+        elif options.script:
+            console = Console(local, histsize=options.histsize)  
+            with open(options.script, 'r') as f:  
+                console.runcode(f.read())  
         else:
             console = InteractiveConsole(local)
             console.runcode(sys.stdin.read())

Hi!
I assume this patch is for a more recent version of Tryton, and I’m using 6.0. Based on the code you shared, I manually adapted it to version 6.0. I also made some modifications so that pdbpp (a drop-in replacement for pdb) doesn’t throw errors when using the “sticky” and “ll” features.

--- commandline.py.orig	2025-09-16 16:13:29.335776000 -0300
+++ commandline.py.modified	2025-09-17 15:37:53.379989097 -0300
@@ -113,6 +113,13 @@
         required=True, metavar='DATABASE', help="specify the database name")
     parser.add_argument("--histsize", dest="histsize", type=int, default=500,
         help="The number of commands to remember in the command history")
+    parser.add_argument(
+        "-f", "--file",
+        dest="script",
+        metavar='FILE',
+        nargs='+',
+        help="Python script(s) to execute"
+    )
     parser.epilog = "To store changes, `transaction.commit()` must be called."
     return parser
 
--- console.py.orig	2025-09-16 16:13:29.339776000 -0300
+++ console.py.modified	2025-09-17 15:42:33.054114243 -0300
@@ -50,14 +50,21 @@
             'pool': pool,
             'transaction': transaction,
             }
-        if sys.stdin.isatty():
+        if sys.stdin.isatty() and not options.script:
             console = Console(local, histsize=options.histsize)
-            banner = "Tryton %s, Python %s on %s" % (
-                __version__, sys.version, sys.platform)
+            banner = "Tryton %s, Python %s on %s" % (__version__, sys.version, sys.platform)
             kwargs = {}
             if sys.version_info >= (3, 6):
                 kwargs['exitmsg'] = ''
             console.interact(banner=banner, **kwargs)
+        elif options.script:
+            console = Console(local, histsize=options.histsize)
+            for script_path in options.script:
+                if not script_path:
+                    continue
+                with open(script_path, 'r') as f:
+                    code = compile(f.read(), script_path, 'exec')
+                    console.runcode(code)
         else:
             console = InteractiveConsole(local)
             console.runcode(sys.stdin.read())

It will be great if somebody contributes the change so it can be included in newer tryton series.