Reimporting¶
Usually not required
KDB-X Python now automatically manages the environment variables needed to reimport it, so in
most cases you can start a subprocess that imports KDB-X Python (or, for a KDB-X 5.0 q
process, loads pykx.q) directly, without PyKXReimport.
PyKXReimport is still required when starting a kdb+ 4.0/4.1 q subprocess from a
Python process that has imported KDB-X Python. Alternatively, set PYKX_IGNORE_QHOME=true
so QHOME is not redirected in the first place.
Refer to QHOME, symlinking and subprocesses for details.
pykx.reimporter
¶
KDB-X Python reimport helper module.
KDB-X Python uses various environment variables to monitor the state of various modules initialization. This is required to manage all of the different modes of operation, however it can cause issues when attempting to reimport KDB-X Python within a spawned subprocess.
This module provides a mechanism to allow users to safely reimport KDB-X Python within spawned subprocesses without having to manually manage any of these internal environment variables.
PyKXReimport
¶
PyKXReimport()
Helper class to help manage the environment variables around reimporting KDB-X Python in a subprocess.
It is strongly recommended to use this class by using the python with syntax. This will ensure
all the environment variables are reset and restored correctly, without the need to manage this
yourself.
Examples:
with kx.PyKXReimport():
# This process can safely import KDB-X Python
subprocess.Popen(f"python other_file.py")
Not required in most cases.
KDB-X Python now automatically manages these environment variables, so this helper is not needed for the majority of use cases (for example spawning a Python subprocess, or a KDB-X 5.0 q process).
Still required for spawning kdb+ 4.0/4.1 q subprocesses from Python.
When KDB-X Python is imported in a Python process it redirects QHOME to its internal
directory. A kdb+ 4.0/4.1 q child inheriting that QHOME fails to start because the
pykx-internal QHOME does not contain q.k. Wrapping the spawn in PyKXReimport restores
the user's QHOME (which contains q.k) for the child. This also applies where the QHOME
symlinks pykx creates are unavailable or unreliable (e.g. Windows). Alternatively set
PYKX_IGNORE_QHOME=true so QHOME is not redirected in the first place.
reset ¶
reset()
Reset all the required environment variables.
It is not recommended to use this function directly instead use the with syntax.
This will automatically manage setting and restoring the environment variables for you.
restore ¶
restore()
Restore all the required environment variables.
It is not recommended to use this function directly instead use the with syntax.
This will automatically manage setting and restoring the environment variables for you.