I need to kill a remote KDB+ session. This can be done in several ways but I'd prefer to use IPC handlers.
I start a KDB+ session:
$ q -p 5000
KDB+ 3.0 2012.11.13 Copyright (C) 1993-2012 Kx Systems
Then I start another KDB session and I manage to kill the server successfully:
$ q
KDB+ 3.0 2012.11.13 Copyright (C) 1993-2012 Kx Systems
q)h: hopen `::5000
q)h(exit;0)
'close
q)\\
But, if I create a script (test.q) with the instructions above, it fails:
$ cat test.q
h: hopen `::5000
h(exit;0)
\\
$ q test.q
KDB+ 3.0 2012.11.13 Copyright (C) 1993-2012 Kx Systems
k){0N!x y}
'close
@
"q"
"h(exit;0)"
q))
Any ideas? I really appreciate.
You are making a synchronous request to the remote server which means that you are expecting a response. The problem is that your request causes the remote server to shut down and close the connection immediately, resulting in an error and causing q to go into debug mode.
If you just want to send an exit to the remote server without causing an error, you can send the request asynchronously by using a negative value for the connection handle (notice the lack of the 'close error):
q)h: hopen `::5000
q)(neg h) (exit;0)
q)\\
I managed to sort this out by using Protected Evaluation:
In test.q file:
h: hopen `::5000
@[h; "exit 0"; {}]
\\
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With