KxSystems / pyq

PyQ — Python for kdb+
http://code.kx.com/q/interfaces
Apache License 2.0
190 stars 49 forks source link

Running a background q timer within an IPython session #136

Open cmccarthy1 opened 4 years ago

cmccarthy1 commented 4 years ago

Issue raised via email to fusion@kx.com, here for posterity

Questions

Steps to reproduce the issue

The following minimal script was provided and should expose the behaviour, named test.q and executed as $ q test.q

t:([]id:();time:());
.ns.i:0;
.z.ts:{
    `t insert (.ns.i;.z.p);
    .ns.i+:1
 };
system"t 2000";
show t;
show string[.z.p]," : Breaking to python"
p)1
.pyq.run:.pyq.py `$1_string .Q.dd[hsym `$getenv `$"CONDA_PREFIX";`bin`pyq];
.pyq.run ("-m";"IPython")

Expected result

Expected behaviour from user was that the timer set initially before running the IPython session would continue to allow the table to be added too on the timer while in the IPython session.

Issue #10 indicates that once in an interactive python environment that the python REPL overrides the kdb main loop however which is likely the reason that the timers do not execute as expected?

Actual result

The timer is not executing in the background. Events can be triggered from direct calls to .z.ts through PyQ via

[1] q('.z.ts[]')

However this is not sufficient in the users use case

Workaround

If you know workaround, please provide it here.

A suitable workaround doesn't appear to be available hence the question. An async threaded python event loop can be run which allows for some level of flexibility but this use case requires that global variables be updated which seems to be outside the remit of the interface in this use case.

Any workarounds/insights into this would be greatly appreciated

github-actions[bot] commented 3 years ago

Stale issue message

github-actions[bot] commented 3 years ago

Stale issue message

github-actions[bot] commented 3 years ago

Stale issue message

github-actions[bot] commented 3 years ago

Stale issue message