1 .. _python_console_page:
7 **Python console** - Window for Python interpreter. This window functions like a standard document:
8 the pop-up menu invoked by right-click in this window gives access to **Copy/Paste/SelectAll/ClearAll** options.
10 You can run a Python script in interactive mode by typing expressions line by line or by loading a Python file
11 from the main menu **File -> Load Script**.
17 By default the console is always initialized in asynchronous mode when the Python commands are executed in the separated thread
18 that does not block the main GUI loop. So, you'll see any intermediate output from the running script even if the script didn't finish yet.
20 In the synchronous mode each Python command is executed in the main GUI thread, then GUI is blocked until the command is finished.
21 It could be an issue if you run a time consuming Python script, because you won't see any output till the end of execution.
23 If you need to run a script in synchronous mode for whatever reason, set ``PYTHON_CONSOLE_SYNC`` environment variable before Salome start:
25 .. code-block:: console
27 export PYTHON_CONSOLE_SYNC=1
33 To output in console currently executed functions, we're adding tracing code to the start and at the end
34 of the command to deactivate it immediately after execution.
36 This mechanism is turned off by default. Set ``PYCONSOLE_TRACE`` before SALOME start to activate it:
38 .. code-block:: console
40 export PYCONSOLE_TRACE=1
42 If the tracing is on while the script is running we can see functions enter and return calls
43 with ``>>`` and ``<<`` marks followed by line number and function name. Tracing function prints only calls to functions
44 defined in the current script to prevent printing of thousands of lines for builtin functions in some cases.
46 Example of a script with defined functions:
48 .. code-block:: python
79 And output in the Python console:
81 .. code-block:: console
83 >>> sys.setprofile(lambda frame, event, arg: print('>>', frame.f_lineno, ': ', frame.f_code.co_name) if event == 'call' and frame.f_code.co_filename == '/home/function_calls.py' and frame.f_code.co_name != '<module>' else print('<<', frame.f_lineno, ': ', frame.f_code.co_name) if event == 'return' and frame.f_code.co_filename == '/home/function_calls.py' and frame.f_code.co_name != '<module>' else None); exec(compile(open('/home/function_calls.py', 'rb').read(), '/home/function_calls.py', 'exec')); sys.setprofile(None);