Skip to content

Commit

Permalink
added timeout to the new posix conditional lower latency port test co…
Browse files Browse the repository at this point in the history
…nnection code
  • Loading branch information
erickmiller committed Sep 6, 2016
1 parent 865c5ad commit 4fc4d7a
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion pyiqfeed/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,19 @@ def launch(self) -> None:
p = subprocess.Popen(iqfeed_call, shell=True,
stdin=subprocess.DEVNULL, stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL)

s = socket.socket()
host = "127.0.0.1"
port = 9400
timeout = 30 #seconds
before = time.time()
connecting = True
while connecting:
try:
s.connect((host, port))
except:
connecting = True
if time.time() - before > timeout:
raise SystemError('Timeout: Can not connect to the iqfeed port...')
else:
connecting = False
s.recv(16384)
Expand Down

0 comments on commit 4fc4d7a

Please sign in to comment.