-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
52 changed files
with
2,528 additions
and
440 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import asyncio | ||
import sys | ||
|
||
|
||
import pykx as kx | ||
|
||
port = 5000 | ||
if len(sys.argv)>1: | ||
port = int(sys.argv[1]) | ||
|
||
|
||
def qval_sync(query): | ||
res = kx.q.value(query) | ||
print("sync") | ||
print(f'{query}\n{res}\n') | ||
return res | ||
|
||
|
||
def qval_async(query): | ||
res = kx.q.value(query) | ||
print("async") | ||
print(f'{query}\n{res}\n') | ||
|
||
|
||
async def main(): | ||
# It is possible to add user validation by overriding the .z.pw function | ||
# kx.q.z.pw = lambda username, password: password == 'password' | ||
kx.q.z.pg = qval_sync | ||
kx.q.z.ps = qval_async | ||
async with kx.RawQConnection(port=port, as_server=True, conn_gc_time=20.0) as q: | ||
while True: | ||
await q.poll_recv_async() | ||
|
||
|
||
if __name__ == "__main__": | ||
asyncio.run(main()) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import pykx as kx | ||
|
||
import asyncio | ||
|
||
|
||
table = kx.q('([] a: 10?10; b: 10?10)') | ||
|
||
|
||
def assert_result(res): | ||
# assert message from q process has the correct schema to be appended to the table | ||
return type(res) is kx.LongVector and len(res) == 2 | ||
|
||
|
||
async def main_loop(q): | ||
global table | ||
while True: | ||
result = await q.poll_recv_async() | ||
if assert_result(result): | ||
print(f'Recieved new table row from q: {result}') | ||
table = kx.q.upsert(table, result) | ||
print(table) | ||
result = None | ||
|
||
|
||
async def main(): | ||
global table | ||
async with kx.RawQConnection(port=5001, event_loop=asyncio.get_event_loop()) as q: | ||
print('===== Initital Table =====') | ||
print(table) | ||
print('===== Initital Table =====') | ||
# Set the variable py_server on the q process pointing towards this processes IPC connection | ||
# We use neg to ensure the messages are sent async so no reply is expected from this process | ||
await q('py_server: neg .z.w') | ||
|
||
await main_loop(q) | ||
|
||
|
||
if __name__ == '__main__': | ||
asyncio.run(main()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.