Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
satella
Manage
Activity
Members
Labels
Plan
Issues
1
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
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
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
public
satella
Commits
332b6e40
Unverified
Commit
332b6e40
authored
9 months ago
by
Piotr Maślanka
Browse files
Options
Downloads
Patches
Plain Diff
added __len__ to PeekableQueue
parent
14f32728
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#62414
failed with stages
in 1 minute and 21 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CHANGELOG.md
+2
-1
2 additions, 1 deletion
CHANGELOG.md
satella/coding/concurrent/queue.py
+8
-3
8 additions, 3 deletions
satella/coding/concurrent/queue.py
with
10 additions
and
4 deletions
CHANGELOG.md
+
2
−
1
View file @
332b6e40
# v.25.a
3
# v.25.a
7
*
fixed circular import
*
fixed circular import
*
added __len__ to PeekableQueue
# v2.25.5
# v2.25.5
...
...
This diff is collapsed.
Click to expand it.
satella/coding/concurrent/queue.py
+
8
−
3
View file @
332b6e40
...
@@ -13,13 +13,14 @@ class PeekableQueue(tp.Generic[T]):
...
@@ -13,13 +13,14 @@ class PeekableQueue(tp.Generic[T]):
"""
"""
A thread-safe FIFO queue that supports peek()ing for elements.
A thread-safe FIFO queue that supports peek()ing for elements.
"""
"""
__slots__
=
(
'
queue
'
,
'
lock
'
,
'
inserted_condition
'
)
__slots__
=
(
'
queue
'
,
'
lock
'
,
'
inserted_condition
'
,
'
items_count
'
)
def
__init__
(
self
):
def
__init__
(
self
):
super
().
__init__
()
super
().
__init__
()
self
.
queue
=
collections
.
deque
()
self
.
queue
=
collections
.
deque
()
self
.
lock
=
threading
.
Lock
()
self
.
lock
=
threading
.
Lock
()
self
.
inserted_condition
=
Condition
()
self
.
inserted_condition
=
Condition
()
self
.
items_count
=
0
def
put
(
self
,
item
:
T
)
->
None
:
def
put
(
self
,
item
:
T
)
->
None
:
"""
"""
...
@@ -29,6 +30,7 @@ class PeekableQueue(tp.Generic[T]):
...
@@ -29,6 +30,7 @@ class PeekableQueue(tp.Generic[T]):
"""
"""
with
self
.
lock
:
with
self
.
lock
:
self
.
queue
.
append
(
item
)
self
.
queue
.
append
(
item
)
self
.
items_count
+=
1
self
.
inserted_condition
.
notify
()
self
.
inserted_condition
.
notify
()
def
put_many
(
self
,
items
:
tp
.
Sequence
[
T
])
->
None
:
def
put_many
(
self
,
items
:
tp
.
Sequence
[
T
])
->
None
:
...
@@ -40,7 +42,7 @@ class PeekableQueue(tp.Generic[T]):
...
@@ -40,7 +42,7 @@ class PeekableQueue(tp.Generic[T]):
with
self
.
lock
:
with
self
.
lock
:
items_count
=
0
items_count
=
0
for
item
in
items
:
for
item
in
items
:
items_count
+=
1
self
.
items_count
+=
1
self
.
queue
.
append
(
item
)
self
.
queue
.
append
(
item
)
self
.
inserted_condition
.
notify
(
items_count
)
self
.
inserted_condition
.
notify
(
items_count
)
...
@@ -114,4 +116,7 @@ class PeekableQueue(tp.Generic[T]):
...
@@ -114,4 +116,7 @@ class PeekableQueue(tp.Generic[T]):
guarantee that a subsequent get() will not block.
guarantee that a subsequent get() will not block.
:return: approximate size of the queue
:return: approximate size of the queue
"""
"""
return
len
(
self
.
queue
)
return
self
.
items_count
def
__len__
(
self
):
return
self
.
items_count
\ No newline at end of file
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