cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
%3CLINGO-SUB%20id%3D%22lingo-sub-782950%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%C2%BFHay%20alguna%20manera%20de%20restablecer%20las%20integraciones%20de%20JMP%20Python%20desde%20el%20lado%20de%20Python%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-782950%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3E%C2%BFHay%20alguna%20forma%20de%20borrar%20%22todo%22%20en%20el%20lado%20Python%20de%20JMP%20sin%20cerrar%20la%20sesi%C3%B3n%20JMP%20(algo%20similar%20a%20Eliminar%20s%C3%ADmbolos()%20en%20JSL%20o%20una%20forma%20de%20reiniciar%20el%20kernel)%3F%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%0A%3CP%3EEstoy%20desarrollando%20una%20aplicaci%C3%B3n%20que%20utiliza%20la%20integraci%C3%B3n%20de%20JMP%20con%20Python%20con%20mi%20colega%20y%2C%20a%20medida%20que%20realizamos%20cambios%20en%20el%20c%C3%B3digo%20Python%2C%20debemos%20cerrar%20JMP%20constantemente.%20Hacemos%20esto%20para%20%22limpiar%22%20Python%20cuando%20nos%20encontramos%20con%20problemas%20en%20los%20que%20el%20c%C3%B3digo%20Python%20antiguo%20est%C3%A1%20en%20la%20memoria%20y%20las%20importaciones%20no%20sobrescriben%20el%20c%C3%B3digo%20ya%20importado.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-782950%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CLINGO-LABEL%3EAutomatizaci%C3%B3n%20y%20scripting%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-782963%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20%C2%BFHay%20alguna%20manera%20de%20restablecer%20las%20integraciones%20de%20JMP%20Python%20desde%20el%20lado%20de%20Python%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-782963%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EM%C3%B3dulos%20actualizados%20que%20se%20ignoran.%20Muchas%20sorpresas%20y%20maravillas...%20hasta%20que%20te%20das%20cuenta...%3CBR%20%2F%3E%20%C2%A1Argh!%3C%2FP%3E%3CP%3E%20%3C%2FP%3E%3CP%3E%C2%BF%20%3CFONT%20face%3D%22courier%20new%2Ccourier%22%3Edel%3C%2FFONT%3E%20funciona%3F%3C%2FP%3E%3CPRE%3E%3CCODE%20class%3D%22%20language-jsl%22%3Eimport%20sys%0Aprint(sys.path)%0Adel%20sys%0Aprint(sys.path)%3C%2FCODE%3E%3C%2FPRE%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-783147%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3ERe%3A%20%C2%BFHay%20alguna%20manera%20de%20restablecer%20las%20integraciones%20de%20JMP%20Python%20desde%20el%20lado%20de%20Python%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-783147%22%20slang%3D%22en-US%22%20mode%3D%22CREATE%22%3E%3CP%3EHay%20%3CEM%3E%3CSTRONG%3Eproblemas%3C%2FSTRONG%3E%3C%2FEM%3E%20.%20En%20la%20mayor%C3%ADa%20de%20los%20scripts%20de%20Python%2C%20el%20problema%20no%20se%20nota%20mucho%20porque%20el%20tiempo%20de%20vida%20de%20Python%20en%20s%C3%AD%20suele%20ser%20el%20mismo%20que%20el%20del%20script.%20Comenzar%C3%ADas%20a%20notarlo%20si%20ejecutaras%20Python%20de%20forma%20interactiva%20durante%20una%20sesi%C3%B3n%20larga%2C%20haciendo%20varias%20cosas%20dentro%20de%20la%20misma%20sesi%C3%B3n%20interactiva.%20Esto%20se%20complica%20a%C3%BAn%20m%C3%A1s%20porque%20algunos%20de%20los%20paquetes%20de%20Python%20se%20implementan%20en%20C%2FC%2B%2B%20(e%20incluso%20Fortran)%2C%20como%20NumPy.%20Python%20los%20carga%20como%20bibliotecas%20compartidas%20y%20no%20hay%20una%20forma%20segura%20de%20descargar%20la%20biblioteca%20compartida%20de%20un%20proceso%20en%20ejecuci%C3%B3n%2C%20aparte%20de%20un%20reinicio.%20JMP%20est%C3%A1%20en%20una%20posici%C3%B3n%20similar%20con%20la%20propia%20biblioteca%20compartida%20de%20Python%2C%20no%20se%20puede%20descargar.%20S%C3%AD%2C%20%3CSTRONG%3E%3CEM%3Edel%3C%2FEM%3E%3C%2FSTRONG%3E%20funciona%20para%20liberar%20objetos.%20Sin%20embargo%2C%20del%20sys%20no%20est%C3%A1%20haciendo%20lo%20que%20podr%C3%ADas%20esperar.%20Esto%20no%20est%C3%A1%20eliminando%20o%20descargando%20el%20'm%C3%B3dulo'%20ni%20descargando%20dlls%20dependientes%2C%20simplemente%20est%C3%A1%20eliminando%20el%20objeto%20'sys'%20que%20contiene%20las%20referencias%20al%20m%C3%B3dulo%20cargado.%20El%20otro%20aspecto%20es%20que%20sys%20es%20un%20m%C3%B3dulo%20integrado%20de%20Python%2C%20no%20lo%20mismo%20que%20un%20m%C3%B3dulo%20cargado.%20Eliminar%20'sys'%20no%20limpia%20ning%C3%BAn%20cambio%20que%20hayas%20podido%20realizar%2C%20por%20ejemplo%20agregar%20otra%20ruta%20a%20sys.path.%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%0A%3CP%3E%3CSPAN%3ESi%20lo%20haces%3A%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%0A%3CPRE%3Esys.path.append('%2Fusr%2Flocal%2Fbin')%0Aprint(sys.path)%0Adel%20sys%0Aprint(sys.path).%20%20%23%20gives%20error%20on%20sys%0Aimport%20sys%0Aprint(sys.path).%20%20%23%20still%20contains%20the%20%2Fusr%2Flocal%2Fbin%20addition%0A%3C%2FPRE%3E%0A%3CP%3ELo%20anterior%20se%20ejecut%C3%B3%20en%20una%20sesi%C3%B3n%20interactiva%20en%20una%20ventana%20de%20terminal.%20Solo%20al%20salir%20de%20Python%20y%20reiniciarlo%20se%20borr%C3%B3%20%2Fusr%2Flocal%2Fbin%20de%20sys.path.%20La%20%C3%BAnica%20forma%20real%20es%20que%20usted%20lleve%20un%20registro%20de%20todas%20las%20variables%20utilizadas%20en%20una%20sesi%C3%B3n%20y%20luego%20las%20elimine%20al%20final%20de%20la%20%22sesi%C3%B3n%22.%20Una%20forma%20ser%C3%ADa%20colocar%20cada%20variable%20en%20una%20lista%20o%20diccionario%20y%20luego%20eliminar%20el%20contenedor%20al%20final%20de%20la%20sesi%C3%B3n.%3C%2FP%3E%0A%3CP%3EEstoy%20investigando%20el%20uso%20de%20subint%C3%A9rpretes%20de%20Python%20que%20podr%C3%ADan%20permitir%20configurar%20c%C3%B3digo%20que%20no%20se%20ejecuta%20en%20el%20entorno%20global.%20La%20idea%20es%20que%20el%20subint%C3%A9rprete%20sea%20independiente%20y%20que%20apagarlo%20act%C3%BAe%20como%20apagar%20y%20reiniciar%20Python.%20En%20la%20actualidad%2C%20no%20he%20encontrado%20una%20forma%20segura%20de%20apagar%20y%20reiniciar%20el%20int%C3%A9rprete%20principal%20de%20Python%20durante%20la%20duraci%C3%B3n%20de%20una%20sesi%C3%B3n%20JMP.%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%0A%3CP%3ELa%20pr%C3%A1ctica%20actual%20de%20Python%20para%20recargar%20un%20m%C3%B3dulo%20(a%20partir%20de%20Python%203.4)%20es%3C%2FP%3E%0A%3CPRE%20class%3D%22lang-py%20s-code-block%22%3E%3CCODE%20class%3D%22hljs%20language-python%22%20data-highlighted%3D%22yes%22%3E%3CSPAN%20class%3D%22hljs-keyword%22%3Eimport%3C%2FSPAN%3E%20importlib%0Aimportlib.reload(modulename)%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3EIntentando%20recargar%20el%20sistema%20da%3C%2FP%3E%0A%3CPRE%3E%26gt%3B%26gt%3B%26gt%3B%20importlib.reload(sys)%0A%3CMODULE%3E%3C%2FMODULE%3E%3C%2FPRE%3E%0A%3CP%3EAl%20recargar%20numpy%2C%20se%20obtiene%20el%20siguiente%20resultado...%3C%2FP%3E%0A%3CPRE%3E%26gt%3B%26gt%3B%26gt%3B%20importlib.reload(np)%0A%2FLibrary%2FFrameworks%2FPython.framework%2FVersions%2F3.11%2Flib%2Fpython3.11%2Fimportlib%2F__init__.py%3A169%3A%20UserWarning%3A%20The%20NumPy%20module%20was%20reloaded%20(imported%20a%20second%20time).%20This%20can%20in%20some%20cases%20result%20in%20small%20but%20subtle%20issues%20and%20is%20discouraged.%0A%20%20_bootstrap._exec(spec%2C%20module)%0A%3CMODULE%3E%3C%2FMODULE%3E%3C%2FPRE%3E%0A%3CP%3ETenga%20en%20cuenta%20la%20advertencia%20para%20el%20usuario%3A%3C%2FP%3E%0A%3CP%3EAdvertencia%20de%20usuario%3A%20el%20m%C3%B3dulo%20NumPy%20se%20volvi%C3%B3%20a%20cargar%20(se%20import%C3%B3%20por%20segunda%20vez).%20En%20algunos%20casos%2C%20esto%20puede%20generar%20problemas%20peque%C3%B1os%20pero%20sutiles%20y%20no%20se%20recomienda.%20_bootstrap._exec(spec%2C%20module)%3C%2FP%3E%0A%3CP%3E%20%3C%2FP%3E%0A%3CP%3EIncluso%20la%20forma%20%22oficial%22%20de%20recargar%20un%20m%C3%B3dulo%20puede%20causar%20problemas.%3C%2FP%3E%0A%3CP%3Eimportlib.reload()%20funciona%20muy%20bien%20cuando%20se%20desarrolla%20un%20m%C3%B3dulo%20Python%20en%20c%C3%B3digo%2C%20ya%20que%20los%20cambios%20en%20el%20c%C3%B3digo%20fuente%20de%20un%20m%C3%B3dulo%20no%20se%20reflejar%C3%A1n%20hasta%20que%20se%20vuelva%20a%20cargar%2C%20lo%20que%20potencialmente%20obliga%20a%20volver%20a%20compilar%20en%20.pyc%20el%20c%C3%B3digo%20Python.%3C%2FP%3E%3C%2FLINGO-BODY%3E
Choose Language Hide Translation Bar
jthi
Super User

Is there a way to reset JMP Python integrations Python side

Is there any way how I could clear "everything" in the Python side of JMP without closing the JMP session (something similar to Delete Symbols() in JSL or a way to restart the kernel)?

 

I'm developing application utilizing JMP Python integration with my colleague and as we make changes to the Python code we have to keep constantly closing JMP. We do this to "clear" the Python as we run into issues where old Python code is in the memory and imports won't overwrite already imported code.

-Jarmo
1 ACCEPTED SOLUTION

Accepted Solutions

Re: Is there a way to reset JMP Python integrations Python side

There are issues.  In most Python scripts, the issue isn't noticed much because the lifetime of Python itself is usually the same as the script.  You would begin to notice if you ran Python interactively for a long session, doing multiple things within the same interactive session.  This is further complicated by some of the Python packages are implemented in C/C++ ( and even Fortran ) such as NumPy.  Python loads these as shared libraries, and there is no safe way to unload the shared library from a running process, other than a restart.  JMP is in a similar position with the Python shared library itself, it can't be unloaded.  Yes, del works to release objects. However, del sys isn't doing what you might expect.  This isn't deleting or unloading the 'module' or unloading dependent dlls, it's simply deleting the 'sys' object that's holding the references to the loaded module.  The other aspect is that sys is a Python built-in module, not the same as a loaded module.  Further deleting 'sys' doesn't clean up any changes you may have made, for example appending another path to sys.path.

 

If you do:

 

sys.path.append('/usr/local/bin')
print(sys.path)
del sys
print(sys.path).  # gives error on sys
import sys
print(sys.path).  # still contains the /usr/local/bin addition

The above was run in an interactive session in a terminal window.  Only exiting Python and restarting cleared the /usr/local/bin from sys.path.  The only real way is for you to keep track of all the variables used in a session and then delete them at the end of the 'session'.  One way would be to put each variable in a list, or dictionary, then delete the container at the end of the session. 

I am researching the use of Python sub-interpreters which could allow setting up code that doesn't run in the global environment, the idea being the sub-interpreter is independent, and shutting down the sub-interpreter would act like a shut down and restart of Python. At present, I haven't found a way to safely shut down and restart the main Python interpreter within the lifetime of a JMP session.

 

 The current Python practice to reload a module ( starting with Python 3.4) is

import importlib
importlib.reload(modulename)

Trying to reload sys gives

>>> importlib.reload(sys)
<module 'sys' (built-in)>

Reloading numpy, gives the following output...

>>> importlib.reload(np)
/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py:169: UserWarning: The NumPy module was reloaded (imported a second time). This can in some cases result in small but subtle issues and is discouraged.
  _bootstrap._exec(spec, module)
<module 'numpy' from '/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/numpy/__init__.py'>

Note the UserWarning:

UserWarning: The NumPy module was reloaded (imported a second time). This can in some cases result in small but subtle issues and is discouraged. _bootstrap._exec(spec, module)

 

Even with the 'official' way of reloading a module can cause issues.  

importlib.reload() works great for when you are developing a Python module in code, since changes to the a module's source will not be reflected until a reload.  Which potentially forces a recompile to .pyc of the Python code.

View solution in original post

2 REPLIES 2
hogi
Level XII

Re: Is there a way to reset JMP Python integrations Python side

Updated modules which are ignored. Many suprises and wonders - till you notice...
Argh!

 

does del work?

import sys
print(sys.path)
del sys
print(sys.path)

Re: Is there a way to reset JMP Python integrations Python side

There are issues.  In most Python scripts, the issue isn't noticed much because the lifetime of Python itself is usually the same as the script.  You would begin to notice if you ran Python interactively for a long session, doing multiple things within the same interactive session.  This is further complicated by some of the Python packages are implemented in C/C++ ( and even Fortran ) such as NumPy.  Python loads these as shared libraries, and there is no safe way to unload the shared library from a running process, other than a restart.  JMP is in a similar position with the Python shared library itself, it can't be unloaded.  Yes, del works to release objects. However, del sys isn't doing what you might expect.  This isn't deleting or unloading the 'module' or unloading dependent dlls, it's simply deleting the 'sys' object that's holding the references to the loaded module.  The other aspect is that sys is a Python built-in module, not the same as a loaded module.  Further deleting 'sys' doesn't clean up any changes you may have made, for example appending another path to sys.path.

 

If you do:

 

sys.path.append('/usr/local/bin')
print(sys.path)
del sys
print(sys.path).  # gives error on sys
import sys
print(sys.path).  # still contains the /usr/local/bin addition

The above was run in an interactive session in a terminal window.  Only exiting Python and restarting cleared the /usr/local/bin from sys.path.  The only real way is for you to keep track of all the variables used in a session and then delete them at the end of the 'session'.  One way would be to put each variable in a list, or dictionary, then delete the container at the end of the session. 

I am researching the use of Python sub-interpreters which could allow setting up code that doesn't run in the global environment, the idea being the sub-interpreter is independent, and shutting down the sub-interpreter would act like a shut down and restart of Python. At present, I haven't found a way to safely shut down and restart the main Python interpreter within the lifetime of a JMP session.

 

 The current Python practice to reload a module ( starting with Python 3.4) is

import importlib
importlib.reload(modulename)

Trying to reload sys gives

>>> importlib.reload(sys)
<module 'sys' (built-in)>

Reloading numpy, gives the following output...

>>> importlib.reload(np)
/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/importlib/__init__.py:169: UserWarning: The NumPy module was reloaded (imported a second time). This can in some cases result in small but subtle issues and is discouraged.
  _bootstrap._exec(spec, module)
<module 'numpy' from '/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/numpy/__init__.py'>

Note the UserWarning:

UserWarning: The NumPy module was reloaded (imported a second time). This can in some cases result in small but subtle issues and is discouraged. _bootstrap._exec(spec, module)

 

Even with the 'official' way of reloading a module can cause issues.  

importlib.reload() works great for when you are developing a Python module in code, since changes to the a module's source will not be reflected until a reload.  Which potentially forces a recompile to .pyc of the Python code.