PyKX could not establish an IPC connection in the Flask app

I’m trying to make a connection from a Flask app, but it shows a QError: .pykx.i.isw.

I tried the same function without a Flask app, and it can make a connection.  Please find attached.

Can you please take a look on it. 

Hi, 

 

What version of PyKX are you using? 

.pykx.i.isw has been renamed to .pykx.util.isw since 2.0.0

 

 

 

 

 

I did a quick test using PyKX 2.2.0:

 

 

python3.10 -m venv flaskTest . flaskTest/bin/activate pip install Flask pip install pykx

 

 

Then I created hello_kx.py:

 

 

from flask import Flask app = Flask( name ) @app.route(“/”) def hello_kx(): import pykx as kx qcon=kx.QConnection(host=‘localhost’, port=5001) tables=qcon(‘tables’).py() return tables

 

 

Then running flask --app hello_kx run and opening my browser I see:

 

 

[“a”, “b”, “c”]

 

 

When working with Python frameworks there may be certain limitations if they are running PyKX inside threads.

Sub processes reimporting PyKX is also something that should be done in a certain way:

https://code.kx.com/pykx/2.2/api/reimporting.html 

 

 

I tried in pykx 1.6.3
pip list | grep pykx
pykx 1.6.3

after updated the package into 2.2.0 - It make a IPC connection, Thanks a lot. 

Hey  , 

I have issue when I setup the flask server like you described, I managed to get the response, but also got error logs like in the image attachment. Do you know something about this?

See: PYKX_SKIP_SIGNAL_OVERWRITE on

https://code.kx.com/pykx/2.2/user-guide/configuration.html

*New in 2.2.1

Thanks for your answer,  ! However, I still find the same error logs even with that config enabled. Not sure if this affects the issue, but I am using Flask 3.0 and PyKX 2.2.1. I have tried using other frameworks such as Django or FastAPI, and both are running fine. So, I wonder whether this problem is specific to Flask. 

Did you manage to find a solution for this? I have the same issue!
Running flask==3.0.0 and pykx==2.2.1

Hello  ,

I tried the same with both pykx 2.2.0 /2.3.0 , python 3.10.9 , Flask 3.0.2, I can’t able to connect with port 5000.

 

from flask import Flask import pykx as kx import json as j app = Flask( name ) @app.route(“/”) def hello_kx(): import pykx as kx qcon=kx.QConnection(host=‘localhost’, port=5000) tables=qcon(“tables”).py() import json as j print(j.dumps(ports)) return tables if name == ’ main’: app.run(host=‘127.0.0.1’, debug=True, port=8100)

 

I got this error: 
if q(‘{.pykx.util.isw x}’, self).py():
File “/rxds/rxds_offerings/datagen/env/lib/python3.10/site-packages/pykx/embedded_q.py”, line 226, in __call__
return factory(result, False)
File “pykx/_wrappers.pyx”, line 507, in pykx._wrappers._factory
File “pykx/_wrappers.pyx”, line 500, in pykx._wrappers.factory
pykx.exceptions.QError: .pykx.util.isw

the same code I just run python without flask it return values.

 

import pykx as kx import json def hello_kx(): qcon=kx.QConnection(host=‘localhost’, port=5000) tables=qcon(“tables”).py() import json return json.dumps(tables) a=hello_kx() print(a)

 

 

You example will run if you wait and only import pykx within the app

from flask import Flask #import pykx as kx <– remove this import json as j app = Flask( name ) @app.route(“/”) def hello_kx(): import pykx as kx qcon=kx.QConnection(host=‘localhost’, port=5000) tables=qcon(“tables”).py() import json as j print(j.dumps(ports)) return tables if name == ’ main’: app.run(host=‘127.0.0.1’, debug=True, port=8100)

Or if you only use PyKX for querying then you can use in unlicensed mode

https://code.kx.com/pykx/2.3/user-guide/advanced/modes.html#operating-in-the-absence-of-a-kx-license 

 

from flask import Flask import os os.environ['PYKX_UNLICENSED']='true' import pykx as kx import json as j app = Flask( __name__ ) @app.route("/") def hello_kx(): #import pykx as kx qcon=kx.QConnection(host='localhost', port=5000) tables=qcon("tables[]").py() #import json as j #print(j.dumps(ports)) return tables if __name__ == ' __main__': app.run(host='127.0.0.1', debug=True, port=8100)