I’m currently writing a script and I would like to run tests on the functionality outside of the “Python Script” node. Is there a way that it can detect from within Python whether it’s currently running within KNIME.
This way I could switch inputs based on an if/else statement.
I’m not sure this is trivial to check externally. I believe KNIME may be running a pool of Python processes at any given time, so it doesn’t suffice to check whether another Python process is running.
Instead, I suggest internalizing this check into the script:
The script could create a .lock file (or whatever you’d like to name it) on disk and remove said file once it completes. That way, you can check whether the script is running by testing for the existence of the .lock file.
@kermitthefrog01 well what you could do is check the presence of the knime module. Of course that would mean the you would use another environment outside KNIME where the specific module is not present.
print("KNIME module is available")
print("KNIME module is not available")
I think that’s the most pragmatic solution for me. The KNIME module isn’t available in my external Python instances, so that should run fine.
I’m not sure I fully understand your approach, could you help me and elaborate a bit on that please?
Where would I create the .lock file - as in which folder, and is it a relative or absolute path? How would I then distinguish whether the .lock file came from KNIME or from another Python instance?
I may have gotten your original question wrong. I assumed you were wanting to check whether the script was already running in any other instance (and the only possible other instance was KNIME).
Reading the question again, I’d also go with the excellent suggestion of @mlauber71.
Ah, okay. No worries.
Thanks for engaging with my question.