improve I/O waiting using select
This commit is contained in:
parent
a89133e955
commit
0026655100
|
|
@ -19,6 +19,7 @@
|
||||||
IS class is used for connection to APRS-IS network
|
IS class is used for connection to APRS-IS network
|
||||||
"""
|
"""
|
||||||
import socket
|
import socket
|
||||||
|
import select
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
|
|
@ -155,6 +156,8 @@ class IS(object):
|
||||||
if not self._connected:
|
if not self._connected:
|
||||||
raise ConnectionError("not connected to a server")
|
raise ConnectionError("not connected to a server")
|
||||||
|
|
||||||
|
line = ''
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
for line in self._socket_readlines(blocking):
|
for line in self._socket_readlines(blocking):
|
||||||
|
|
@ -265,8 +268,10 @@ class IS(object):
|
||||||
while True:
|
while True:
|
||||||
short_buf = ''
|
short_buf = ''
|
||||||
|
|
||||||
|
select.select([self.sock], [], [], None if blocking else 0)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
short_buf = self.sock.recv(1024)
|
short_buf = self.sock.recv(4096)
|
||||||
|
|
||||||
# sock.recv returns empty if the connection drops
|
# sock.recv returns empty if the connection drops
|
||||||
if not short_buf:
|
if not short_buf:
|
||||||
|
|
@ -285,7 +290,3 @@ class IS(object):
|
||||||
line, self.buf = self.buf.split("\r\n", 1)
|
line, self.buf = self.buf.split("\r\n", 1)
|
||||||
|
|
||||||
yield line
|
yield line
|
||||||
|
|
||||||
# lets not hog the CPU when there's nothing to do
|
|
||||||
if blocking:
|
|
||||||
time.sleep(0.1)
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue