Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Socket stale when opening port in PyQ #3

Closed
sitsang opened this issue Oct 18, 2016 · 3 comments
Closed

Socket stale when opening port in PyQ #3

sitsang opened this issue Oct 18, 2016 · 3 comments
Assignees
Labels

Comments

@sitsang
Copy link

sitsang commented Oct 18, 2016

KDB+/Q supports socket connection natively. But when activating the socket listener in Q, it will not response when inside PyQ.

Server Side:

>>> pyq.q("\p 12345")
k('::')

Client Side:

>>> import pyq
>>> pyq.q("hopen `::12345")

The hopen command will wait for a long time, it seems the server side isn't responding.

@abalkin
Copy link
Contributor

abalkin commented Oct 18, 2016

This is expected behavior. When you run pyq, q event loop is blocked in a call to Python's main loop. To avoid this, you should call python from a regular q session. For example:

Server side:

$ q
KDB+ 3.4 2016.06.14 ..
q)p)from pyq import q
q)p)def f(): print 'Hello';return q('42') # make sure to return a K object
q)p)q.f = f   # export f to q (make sure not to delete f in python)
q)f()  / check that we can call f locally
Hello
42
q)\p 1024  /  now open the communication port

Client side:

$ q
KDB+ 3.4 2016.06.14 ..
q)`::1024 "f()"
42

and 'Hello' is printed on the server side.

If you don't want to prefix every line with p) you can put your python code in a file with .p extension and load it from q

$ cat f.p
from pyq import q
def f():
    print 'Hello'
    return q('42')
q.f = f
$ q
KDB+ 3.4 2016.06.14 ..
q)\l f.p
q)f()
Hello
42

@abalkin abalkin self-assigned this Oct 18, 2016
@sitsang
Copy link
Author

sitsang commented Oct 18, 2016

Actually, I am using PyQ inside Apache Spark via pyspark, so the server's entry point must be from python.

Can you show me where the event loop is blocked in the python's main loop?

@abalkin
Copy link
Contributor

abalkin commented Oct 18, 2016

Can you show me where the event loop is blocked in the python's main loop?

At this line in python.q. Note that the pyq command is more or less q python.q.

@abalkin abalkin added the wontfix label Mar 9, 2017
@abalkin abalkin closed this as completed Mar 9, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants