Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
D
douban-api-proxy
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
captainwong
douban-api-proxy
Commits
88427009
Commit
88427009
authored
Aug 31, 2020
by
OzzieIsaacs
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'worker/tasks' into Develop
parents
1a9a436c
ef49e2b5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
2 deletions
+12
-2
worker.py
cps/services/worker.py
+12
-2
No files found.
cps/services/worker.py
View file @
88427009
...
@@ -3,6 +3,7 @@ from __future__ import division, print_function, unicode_literals
...
@@ -3,6 +3,7 @@ from __future__ import division, print_function, unicode_literals
import
threading
import
threading
import
abc
import
abc
import
uuid
import
uuid
import
time
try
:
try
:
import
queue
import
queue
...
@@ -102,8 +103,17 @@ class WorkerThread(threading.Thread):
...
@@ -102,8 +103,17 @@ class WorkerThread(threading.Thread):
def
run
(
self
):
def
run
(
self
):
main_thread
=
_get_main_thread
()
main_thread
=
_get_main_thread
()
while
main_thread
.
is_alive
():
while
main_thread
.
is_alive
():
# this blocks until something is available
try
:
item
=
self
.
queue
.
get
()
# this blocks until something is available. This can cause issues when the main thread dies - this
# thread will remain alive. We implement a timeout to unblock every second which allows us to check if
# the main thread is still alive.
# We don't use a daemon here because we don't want the tasks to just be abruptly halted, leading to
# possible file / database corruption
item
=
self
.
queue
.
get
(
timeout
=
1
)
except
queue
.
Empty
as
ex
:
time
.
sleep
(
1
)
continue
with
self
.
doLock
:
with
self
.
doLock
:
# add to list so that in-progress tasks show up
# add to list so that in-progress tasks show up
self
.
dequeued
.
append
(
item
)
self
.
dequeued
.
append
(
item
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment