X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=doc%2Fsalome%2Fgui%2Finput%2Fworking_with_python_console.rst;fp=doc%2Fsalome%2Fgui%2Finput%2Fworking_with_python_console.rst;h=0000000000000000000000000000000000000000;hb=5129aefccbb1b0c0d969dd258d324881b2794cdd;hp=e0d84ffbb24eba870fd5cec8f4478fad7e1fe027;hpb=e1ce73d5be167bde706ee8af330ceb3fc952a2e4;p=modules%2Fgui.git diff --git a/doc/salome/gui/input/working_with_python_console.rst b/doc/salome/gui/input/working_with_python_console.rst deleted file mode 100644 index e0d84ffbb..000000000 --- a/doc/salome/gui/input/working_with_python_console.rst +++ /dev/null @@ -1,93 +0,0 @@ -.. _python_console_page: - -****************** -Python Console -****************** - -**Python console** - Window for Python interpreter. This window functions like a standard document: -the pop-up menu invoked by right-click in this window gives access to **Copy/Paste/SelectAll/ClearAll** options. - -You can run a Python script in interactive mode by typing expressions line by line or by loading a Python file -from the main menu **File -> Load Script**. - -================== -Asynchronous mode -================== - -By default the console is always initialized in asynchronous mode when the Python commands are executed in the separated thread -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. - -In the synchronous mode each Python command is executed in the main GUI thread, then GUI is blocked until the command is finished. -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. - -If you need to run a script in synchronous mode for whatever reason, set ``PYTHON_CONSOLE_SYNC`` environment variable before Salome start: - -.. code-block:: console - - export PYTHON_CONSOLE_SYNC=1 - -================== -Tracing -================== - -To output in console currently executed functions, we're adding tracing code to the start and at the end -of the command to deactivate it immediately after execution. - -This mechanism is turned off by default. Set ``PYCONSOLE_TRACE`` before SALOME start to activate it: - -.. code-block:: console - - export PYCONSOLE_TRACE=1 - -If the tracing is on while the script is running we can see functions enter and return calls -with ``>>`` and ``<<`` marks followed by line number and function name. Tracing function prints only calls to functions -defined in the current script to prevent printing of thousands of lines for builtin functions in some cases. - -Example of a script with defined functions: - -.. code-block:: python - :linenos: - - #!/usr/bin/env python - - import time - - def sum(x, y): - time.sleep(3) - return x + y - - def sub(x, y): - time.sleep(3) - return x - y - - def prod(x, y): - time.sleep(3) - return x * y - - def div(x, y): - time.sleep(3) - return x / y - - x = 5 - y = 2 - - sum(x, y) - sub(x, y) - prod(x, y) - div(x, y) - -And output in the Python console: - -.. code-block:: console - - >>> 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 != '' 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 != '' else None); exec(compile(open('/home/function_calls.py', 'rb').read(), '/home/function_calls.py', 'exec')); sys.setprofile(None); - >> 5 : sum - << 7 : sum - >> 9 : sub - << 11 : sub - >> 13 : prod - << 15 : prod - >> 17 : div - << 19 : div - >>> -