cancel
Showing results for 
Search instead for 
Did you mean: 

What does a 0 handle id mean?

hoffmanroni
New Contributor III
Wondering if someone can help.

I am making a connection to a q server but getting a 0 handle id back.

q) h:hopen `:host:port:user:pword
q) h
0i


I am able to query but when I try to close I see domain error

q) h "2+2"
4
q) hclose h
ERROR: 'domain 


Thanks
9 REPLIES 9

Jamie_O__Mahony
New Contributor
New Contributor
Most likely you're opening a handle to your current q session:

q)\p
34067i
q
)hh:hopen 34067
q
)hh
0i
q
)hh"2+2"
4
q
)hclose hh
'domain
  [1]  hclose hh
       ^
  [0]  (.z.pi)



Ha sorry my fault bug on my side.  Thank you

Joseph_griffith
New Contributor
Hi Roni,

This handle you are writing to is actually the console process. 

q)\p 1234
q
)h:hopen 1234
q
)h
0i

The most common use for this is when you are using slaves, when the 0 handle can be used to run on the main thread. When running without slaves this will just just be like running the expression normally with one possible difference being that process timeouts may still occur if the -T flag is set.

You can find more information about it here:https://code.kx.com/q/ref/filenumbers/#0-console

Oh I see, thanks for this


Roni Hoffman
1-519-859-1082

>when you are using slaves, when the 0 handle can be used to run on the main thread.
using handle 0 executes on the current thread, not necessarily the main thread.

q)\s
4i
q){0(set;`a;x)}each til 4
`a`a`a`a
q){0(set;`a;x)}peach til 4
'noupdate: `. `a

Flying
New Contributor III
I'm really curoius, is there is way to send a message from a slave thread back to the main thread to allow parallel processing that have some side effects?

One possible use case is to generate large amount of data in parallel, and send those data to a remote process for futher processing. With the restrictions on slave thread, I obviously cannot use IPC handles directly in the slaves. Due the total data size generated, OTOH, it is also not possible to collect all data back into the main thread before sending them out. And ideal system should be able to simple generate data in parallel, and stream them out into remote processes.

charlie
New Contributor II
New Contributor II
why can't you collect them in the main thread for sending?
As of v3.5 data returned from slave threads is not serialized.

Flying
New Contributor III
How do I collect them into main thread without going 'wsfull?

f peach til 1000000

Each invocation to f returns a lot of data (and each invocation takes a relatively long time). So trying to wait for the above line to complete will both consume a lot of time and cause 'wsfull eventually. That's why the intention was to allow f to send out the generated data incrementally -- this allows downstream processes to start ASAP and avoids the unnecessary 'wsfull in the current process.

_Oz_
New Contributor
Easy 😉 You've hopened the same instance you were on. 0 handle (self) is useful for some things 😉 you don't need to hopen it to use, and obviously you can't close it.

NB. Stuff you're executing on 0 handle goes to .z.ps, but executed synchronously returning result.

Cheers,
Oleg