Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
HEV - High Energy Ventilator
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
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
Projects
HEV - High Energy Ventilator
Commits
2b7e385e
Commit
2b7e385e
authored
4 years ago
by
Dónal Murray
Browse files
Options
Downloads
Patches
Plain Diff
Fix reading and writing receive queue at the same time with lock and deepcopy
parent
f4885f14
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
raspberry-dataserver/CommsControl.py
+12
-6
12 additions, 6 deletions
raspberry-dataserver/CommsControl.py
with
12 additions
and
6 deletions
raspberry-dataserver/CommsControl.py
+
12
−
6
View file @
2b7e385e
...
...
@@ -8,6 +8,7 @@ from serial.tools import list_ports
import
threading
import
time
import
copy
import
CommsFormat
import
CommsCommon
...
...
@@ -282,27 +283,32 @@ class CommsControl():
# callback to dependants to read the received payload
@property
def
payloadrecv
(
self
):
return
self
.
_payloadrecv
with
self
.
_dvlock
:
return
self
.
_payloadrecv
@payloadrecv.setter
def
payloadrecv
(
self
,
payload
):
self
.
_payloadrecv
.
append
(
payload
)
with
self
.
_dvlock
:
self
.
_payloadrecv
.
append
(
payload
)
payloadrecv
=
copy
.
deepcopy
(
self
.
_payloadrecv
)
logging
.
debug
(
f
"
Pushed
{
payload
}
to FIFO
"
)
for
callback
in
self
.
_observers
:
# peek at the leftmost item, don't pop until receipt confirmed
callback
(
self
.
_
payloadrecv
[
0
])
callback
(
payloadrecv
[
0
])
def
bind_to
(
self
,
callback
):
self
.
_observers
.
append
(
callback
)
def
pop_payloadrecv
(
self
):
# from callback. confirmed receipt, pop value
poppedval
=
self
.
_payloadrecv
.
popleft
()
with
self
.
_dvlock
:
poppedval
=
self
.
_payloadrecv
.
popleft
()
payloadrecv
=
copy
.
deepcopy
(
self
.
_payloadrecv
)
logging
.
debug
(
f
"
Popped
{
poppedval
}
from FIFO
"
)
if
len
(
self
.
_
payloadrecv
)
>
0
:
if
len
(
payloadrecv
)
>
0
:
# purge full queue if Dependant goes down when it comes back up
for
callback
in
self
.
_observers
:
callback
(
self
.
_
payloadrecv
[
0
])
callback
(
payloadrecv
[
0
])
# start as interactive session to be able to send and receive
if
__name__
==
"
__main__
"
:
...
...
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