Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
MetObsCommon
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MetObs
MetObsCommon
Commits
c974f4fd
Verified
Commit
c974f4fd
authored
1 year ago
by
David Hoese
Browse files
Options
Downloads
Patches
Plain Diff
Set socket timeout on loggernet receiver
parent
cb58f89a
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
metobscommon/archive/loggernet_receiver.py
+14
-3
14 additions, 3 deletions
metobscommon/archive/loggernet_receiver.py
with
14 additions
and
3 deletions
metobscommon/archive/loggernet_receiver.py
+
14
−
3
View file @
c974f4fd
...
...
@@ -19,14 +19,24 @@ LOG = logging.getLogger(__name__)
def
_ldmp_worker
(
host
,
port
,
queue
,
run_event
):
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
s
.
connect
((
host
,
port
))
s
.
settimeout
(
30.0
)
data_str
=
""
while
run_event
.
is_set
():
# Get the data from the LDMP server
while
not
data_str
or
data_str
[
-
1
]
!=
'
\n
'
:
data
=
s
.
recv
(
2048
)
try
:
data
=
s
.
recv
(
2048
)
except
TimeoutError
:
LOG
.
info
(
"
Timeout error (30 seconds) from LDMP socket
"
)
if
not
run_event
.
is_set
():
LOG
.
debug
(
"
Signal to stop background process seen during receive timeout
"
)
break
data_str
+=
data
.
decode
(
'
utf8
'
)
if
not
run_event
.
is_set
():
continue
# Acknowledge that we received the record
s
.
send
(
b
'
\r
'
)
...
...
@@ -63,9 +73,10 @@ class LDMPReceiver(object):
if
not
self
.
_started
:
return
self
.
_run_event
.
clear
()
LOG
.
info
(
"
Background process told to stop
"
)
self
.
_worker
.
join
()
self
.
_started
=
False
LOG
.
info
(
"
Background
thread
successfully terminated
"
)
LOG
.
info
(
"
Background
process
successfully terminated
"
)
def
close
(
self
):
return
self
.
stop
()
...
...
@@ -80,7 +91,7 @@ class LDMPReceiver(object):
def
__iter__
(
self
):
try
:
while
True
:
yield
self
.
_queue
.
get
(
timeout
=
6
00
)
# 5 minutes
yield
self
.
_queue
.
get
(
timeout
=
3
00
)
# 5 minutes
except
KeyboardInterrupt
:
LOG
.
info
(
"
Keyboard interrupt encountered, killing background
"
"
thread...
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment