Search code examples
pythonkdb+qpython

Multiple KDB+ ticker plant subscriptions in qPython


I'm working on a project where I have a few tables in kdb+ and I'd like to be able to subscribe to one or more of them at a time.

Now I looked at the subscription example they provided and the subscription seems to be set on the connection itself. So as far as I understand for multiple subscriptions I would need multiple connections. Seems a bit tedious to me. Might there be a way to do this with just one connection?

Also, in the example mentioned above there is a thread for each subscription that's looping constantly and checking for new data. Is there any way to do this trigger-event-callback style?

Performance is a necessity, so I'm trying to explore whats possible.

Thanks in advance!


Solution

  • In the example, in the main definition, you can see a call to .u.sub with the tablename as a (symbol) argument. Make this call for each table to which you wish to subscribe. Ensure your handler in the run loop knows which table it's getting - a publisher calls upd on its subscribers, with tablename and data as the arguments.

    With regards trigger-event-callback - you'll have to write your own (or wrap around other Python packages which do similar - see e.g. Twisted).