KX Community

Find answers, ask questions, and connect with our KX Community around the world.
KX Community Guidelines

Home Forums kdb+ Process requests before continuing with script Reply To: Process requests before continuing with script

  • pgyorok

    Member
    August 5, 2024 at 9:11 am

    In order to process incoming connections, the q interpreter must be in its main loop, which will not happen if it is executing code (e.g. the while loop). So if you have code that must be run after such interaction, you will have to come up with a dependency system to execute the code after certain conditions are fulfilled. One example of this is inithook (kdb/q/inithook at main · finos/kdb · GitHub).

    The q process will stay alive as long as it has at least one input handle open – that could be the IPC port but also stdin, so if you make sure that your process has a stdin (e.g. by running it in docker with the -it options) it will stay alive. However there should not be a problem with opening a port just to keep it alive. Use \p 0W to open a random port without the risk of hitting a “port already in use” error. If the concern is random processes connecting, you could use firewall rules to block incoming connections or set the .z.ac/.z.pw handlers to always return false so all connections are rejected.