Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
M
magicCards
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
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
Thomas Letzgus
magicCards
Commits
b1c32a4e
Commit
b1c32a4e
authored
2 years ago
by
Thomas Letzgus
Browse files
Options
Downloads
Patches
Plain Diff
Upload New File
parent
c2a19bec
Branches
letzgus-master-patch-88183
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
consumer.py
+33
-0
33 additions, 0 deletions
consumer.py
with
33 additions
and
0 deletions
consumer.py
0 → 100644
+
33
−
0
View file @
b1c32a4e
from
buffer
import
Buffer
import
threading
import
random
import
time
class
Consumer
:
def
__init__
(
self
,
buffer_obj
):
self
.
buffer
=
buffer_obj
def
consume
(
self
):
while
True
:
time
.
sleep
(
random
.
uniform
(
0.5
,
2.0
))
# Random interval between checks
with
self
.
buffer
.
condition
:
while
self
.
buffer
.
empty
():
self
.
buffer
.
condition
.
wait
()
# Wait until buffer is not empty
car
=
self
.
buffer
.
pop
()
print
(
"
Consumer: Car
"
,
car
.
get_car_id
(),
"
parked out
"
)
if
self
.
buffer
.
full
():
# Buffer was completely full before the withdrawal, wake up all sleeping producers
self
.
buffer
.
condition
.
notify_all
()
# Example usage:
buffer
=
Buffer
(
size
=
10
)
# Assuming buffer is already initialized with a size of 10
consumer
=
Consumer
(
buffer
)
# Create and start the consumer thread
consumer_thread
=
threading
.
Thread
(
target
=
consumer
.
consume
)
consumer_thread
.
start
()
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