cjm2671
cjm2671

Reputation: 19486

How can I make KDB sleep for 5 seconds?

I've got a rate-limited endpoint I'm querying, and so I need to make KDB pause between requests. Is there a way I can block the current thread?

Upvotes: 1

Views: 1980

Answers (3)

kylebonnes
kylebonnes

Reputation: 936

The solutions using system are good for the majority of use cases. If you want an OS-agnostic method, the below lambda can be used, passing the time to wait as an argument:

{t:.z.p;while[.z.p<t+x]} 00:00:05

This approach can also be used if you're making these requests using secondary/slave threads (for example, using peach), whereas attempting to use the system keyword will fail in this case.

Upvotes: 3

Matt Moore
Matt Moore

Reputation: 2800

system"timeout 5"

on Windows OS

For reference system lets you run any commands native to the OS. Like doing \ in the terminal e.g. \timeout 5 ~ system"timeout 5"

Upvotes: 1

terrylynch
terrylynch

Reputation: 13657

You can use

system"sleep 5"

on linux OS

Upvotes: 1

Related Questions