# hopen with timeout

**URL:** <https://forum.kx.com/t/hopen-with-timeout/11790>\
**Category:** Community Support\
**Tags:** kdb-and-q\
**Created:** [July 3, 2018, 12:57am UTC](https://forum.kx.com/t/hopen-with-timeout/11790 "2018-07-03T00:57:00Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sudhakar1](https://avatars.discourse-cdn.com/v4/letter/s/54ee81/32.png) [@sudhakar1](https://forum.kx.com/u/sudhakar1)\
**Post date:** [July 3, 2018, 12:57am UTC](https://forum.kx.com/t/hopen-with-timeout/11790/1 "2018-07-03T00:57:00Z")

</div>

hopen(`::5000;10000) works fine when there is a q session with port 5000.  
But it gives an error if there is no q session on port 5000.

I was hoping it will wait 10 seconds before trying again. But it fails right away.

Has anyone used hopen with a timeout?

---

<div class="post-metadata">

**Author:** ![Flying1](https://avatars.discourse-cdn.com/v4/letter/f/f4b2a3/32.png) [@Flying1](https://forum.kx.com/u/Flying1)\
**Post date:** [July 3, 2018, 2:43am UTC](https://forum.kx.com/t/hopen-with-timeout/11790/2 "2018-07-03T02:43:00Z")

</div>

This hopen timeout is more for the case when the remote process is not responsive during connection (busy with another query, in debug mode, etc.). When there is no process listening on the target port, hopen fails straightaway. If you do want a hopen-with-retry kind of semantics, it’d better to just write your little wrapper around hopen with a while loop or something similar.

---

<div class="post-metadata">

**Author:** ![User7](https://avatars.discourse-cdn.com/v4/letter/u/7ea924/32.png) [@User7](https://forum.kx.com/u/User7)\
**Post date:** [July 3, 2018, 10:04am UTC](https://forum.kx.com/t/hopen-with-timeout/11790/3 "2018-07-03T10:04:00Z")

</div>

This might help:&nbsp;

{h::@[hopen;(`:host:port:user:pass);0];while[0=h;system"sleep 5";h::@[hopen;(`:host:port:user:pass);0]]}

Regards

Alex   
  
On Tuesday, 3 July 2018 00:57:53 UTC+1, sudhakar wrote:

> hopen(`::5000;10000) works fine when there is a q session with port 5000.  
> But it gives an error if there is no q session on port 5000.
> 
> I was hoping it will wait 10 seconds before trying again. But it fails right away.
> 
> Has anyone used hopen with a timeout?
