# Timeout on a sync call

**URL:** <https://forum.kx.com/t/timeout-on-a-sync-call/12108>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [January 21, 2021, 4:01pm UTC](https://forum.kx.com/t/timeout-on-a-sync-call/12108 "2021-01-21T16:01:00Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![newstudent20171](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@newstudent20171](https://forum.kx.com/u/newstudent20171)\
**Post date:** [January 21, 2021, 4:01pm UTC](https://forum.kx.com/t/timeout-on-a-sync-call/12108/1 "2021-01-21T16:01:00Z")

</div>

How do I put a **timeout** on the following **sync** call ?

h:hopen `:192.168.12.15:5001

@[h;`func;{0N!x}]

The other approach is doing an async call and putting a timeout on the callback. This is something I am **not** looking for.

Thanks.

---

<div class="post-metadata">

**Author:** ![matthew\_clark](https://avatars.discourse-cdn.com/v4/letter/m/c2a13f/32.png) [@matthew\_clark](https://forum.kx.com/u/matthew_clark)\
**Post date:** [January 21, 2021, 4:29pm UTC](https://forum.kx.com/t/timeout-on-a-sync-call/12108/2 "2021-01-21T16:29:00Z")

</div>

For a sync call you can specify a timeout for a single query using a format like `::[(“:host:port”;timeout);query], an example would be:

`::[(“:localhost:5000:username:password”;5000);“2+3”]

This is available since&nbsp;V4.0 2020.03.09. If you wanted a more permanent solution you could use either of the -T flag when starting up the q process or the \T command from within a q session followed by the timeout specification you want. However this timeout will hold true for all things executed in the session, not just sync calls.

See the following pages for more information:  
https://code.kx.com/q/ref/hopen/

https://stackoverflow.com/questions/23010704/how-to-set-maximum-execution-time-for-kdb-query&nbsp;&nbsp;

Hope this helps,&nbsp;  
Matthew

---

<div class="post-metadata">

**Author:** ![newstudent20171](https://avatars.discourse-cdn.com/v4/letter/n/c68b51/32.png) [@newstudent20171](https://forum.kx.com/u/newstudent20171)\
**Post date:** [January 21, 2021, 6:39pm UTC](https://forum.kx.com/t/timeout-on-a-sync-call/12108/3 "2021-01-21T18:39:00Z")

</div>

Thanks Matthew.

“…all things executed in the session, not just sync calls…”

Does this mean **any** call in for the **same session** could introduce a timeout (unknowingly) for **ALL** the other calls for the same session **too**?

---

<div class="post-metadata">

**Author:** ![jwbuitenhuis](https://avatars.discourse-cdn.com/v4/letter/j/45deac/32.png) [@jwbuitenhuis](https://forum.kx.com/u/jwbuitenhuis)\
**Post date:** [January 21, 2021, 7:25pm UTC](https://forum.kx.com/t/timeout-on-a-sync-call/12108/4 "2021-01-21T19:25:00Z")

</div>

Not a one-size-fits-all issue.. why do you need a timeout on the client in this case?

There’s timeouts for opening a handle and for running a query.

hopen(`::4000;3000) = timeout on opening the connection.

The \T works on the incoming calls, i.e. the 0 handle. “All” is a strong term here, I think you’ll find exceptions.

You can (ab)use this by running something on the 0-handle:

No interrupt:

q)system"T 1";do[10000000;sqrt 2];  
q)

Interrupt:

q)system"T 1";0({do[10000000;sqrt 2]};`)  
'stop  
 [1] {do[10000000;sqrt 2]}  
 ^
