Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
dm-docs
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package 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
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
hammonds
dm-docs
Commits
09b8150a
Commit
09b8150a
authored
9 years ago
by
sveseli
Browse files
Options
Downloads
Patches
Plain Diff
reworked file processing manager and thread to shutdown cleanly and avoid busy wait
parent
a8559e3f
No related branches found
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/python/dm/common/processing/fileProcessingManager.py
+12
-10
12 additions, 10 deletions
src/python/dm/common/processing/fileProcessingManager.py
src/python/dm/common/processing/fileProcessingThread.py
+29
-24
29 additions, 24 deletions
src/python/dm/common/processing/fileProcessingThread.py
with
41 additions
and
34 deletions
src/python/dm/common/processing/fileProcessingManager.py
+
12
−
10
View file @
09b8150a
...
...
@@ -58,7 +58,7 @@ class FileProcessingManager(threading.Thread,Singleton):
(
moduleName
,
className
,
constructor
)
=
cm
.
getModuleClassConstructorTuple
(
value
)
self
.
logger
.
debug
(
'
Creating file processor instance of class %s
'
%
className
)
fileProcessor
=
ObjectUtility
.
createObjectInstance
(
moduleName
,
className
,
constructor
)
self
.
logger
.
debug
(
'
Configring file processor %s
'
%
fileProcessor
)
self
.
logger
.
debug
(
'
Config
u
ring file processor %s
'
%
fileProcessor
)
fileProcessor
.
setNumberOfRetries
(
self
.
defaultNumberOfRetries
)
fileProcessor
.
setRetryWaitPeriodInSeconds
(
self
.
defaultRetryWaitPeriodInSeconds
)
fileProcessor
.
configure
()
...
...
@@ -67,8 +67,8 @@ class FileProcessingManager(threading.Thread,Singleton):
self
.
fileProcessorKeyList
.
sort
()
self
.
logger
.
debug
(
'
File processor keys: %s
'
%
self
.
fileProcessorKeyList
)
def
process
Observed
File
(
self
,
observedFile
):
self
.
fileProcessingQueue
.
push
(
observedFile
)
def
processFile
(
self
,
fileInfo
):
self
.
fileProcessingQueue
.
push
(
fileInfo
)
self
.
eventFlag
.
set
()
def
start
(
self
):
...
...
@@ -77,24 +77,23 @@ class FileProcessingManager(threading.Thread,Singleton):
self
.
logger
.
debug
(
'
Starting file processing threads
'
)
for
i
in
range
(
0
,
self
.
nProcessingThreads
):
tName
=
'
FileProcessingThread-%s
'
%
i
t
=
FileProcessingThread
(
tName
,
self
.
eventFlag
,
self
.
fileProcessorDict
,
self
.
fileProcessorKeyList
,
self
.
fileProcessingQueue
,
self
.
processedFileDict
,
self
.
unprocessedFileDict
)
t
=
FileProcessingThread
(
tName
,
self
,
self
.
fileProcessorDict
,
self
.
fileProcessorKeyList
,
self
.
fileProcessingQueue
,
self
.
processedFileDict
,
self
.
unprocessedFileDict
)
t
.
start
()
self
.
fileProcessingThreadDict
[
tName
]
=
t
finally
:
self
.
lock
.
release
()
def
stop
(
self
):
self
.
logger
.
debug
(
'
Stopping file processing threads
'
)
for
(
tName
,
t
)
in
self
.
fileProcessingThreadDict
.
items
():
t
.
stop
()
self
.
lock
.
acquire
()
try
:
self
.
logger
.
debug
(
'
Stopping file processing threads
'
)
for
(
tName
,
t
)
in
self
.
fileProcessingThreadDict
.
items
():
t
.
stop
()
self
.
eventFlag
.
set
()
for
(
tName
,
t
)
in
self
.
fileProcessingThreadDict
.
items
():
t
.
join
()
finally
:
self
.
lock
.
release
()
for
(
tName
,
t
)
in
self
.
fileProcessingThreadDict
.
items
():
t
.
join
()
def
setEvent
(
self
):
self
.
lock
.
acquire
()
...
...
@@ -110,6 +109,9 @@ class FileProcessingManager(threading.Thread,Singleton):
finally
:
self
.
lock
.
release
()
def
waitOnEvent
(
self
,
timeoutInSeconds
=
None
):
self
.
eventFlag
.
wait
(
timeoutInSeconds
)
####################################################################
# Testing
...
...
This diff is collapsed.
Click to expand it.
src/python/dm/common/processing/fileProcessingThread.py
+
29
−
24
View file @
09b8150a
...
...
@@ -6,12 +6,14 @@ from dm.common.utility.loggingManager import LoggingManager
class
FileProcessingThread
(
threading
.
Thread
):
def
__init__
(
self
,
name
,
eventFlag
,
fileProcessorDict
,
fileProcessorKeyList
,
fileProcessingQueue
,
processedFileDict
,
unprocessedFileDict
):
THREAD_EVENT_TIMEOUT_IN_SECONDS
=
10.0
def
__init__
(
self
,
name
,
fileProcessingManager
,
fileProcessorDict
,
fileProcessorKeyList
,
fileProcessingQueue
,
processedFileDict
,
unprocessedFileDict
):
threading
.
Thread
.
__init__
(
self
)
self
.
setName
(
name
)
self
.
exitFlag
=
False
self
.
eventFlag
=
eventFlag
self
.
fileProcessingManager
=
fileProcessingManager
self
.
fileProcessorDict
=
fileProcessorDict
self
.
fileProcessorKeyList
=
fileProcessorKeyList
self
.
fileProcessingQueue
=
fileProcessingQueue
...
...
@@ -22,55 +24,58 @@ class FileProcessingThread(threading.Thread):
def
run
(
self
):
self
.
logger
.
debug
(
'
Starting thread: %s
'
%
self
.
getName
())
while
True
:
self
.
fileProcessingManager
.
clearEvent
()
if
self
.
exitFlag
:
self
.
logger
.
debug
(
'
Exit flag
set, %s done
'
%
self
.
getName
()
)
self
.
logger
.
debug
(
'
Exit flag
is set
'
)
break
while
True
:
file
=
self
.
fileProcessingQueue
.
pop
()
if
file
is
None
:
file
Info
=
self
.
fileProcessingQueue
.
pop
()
if
file
Info
is
None
:
break
filePath
=
file
.
getFilePath
()
daqPath
=
file
.
getDaqPath
()
experiment
=
file
.
getExperiment
()
filePath
=
fileInfo
.
get
(
'
filePath
'
)
try
:
for
processorKey
in
self
.
fileProcessorKeyList
:
processor
=
self
.
fileProcessorDict
.
get
(
processorKey
)
processorName
=
processor
.
__class__
.
__name__
fileProcessedByDict
=
file
.
get
(
'
processedByDict
'
,
{})
fileProcessedByDict
=
fileInfo
.
get
(
'
processedByDict
'
,
{})
fileInfo
[
'
processedByDict
'
]
=
fileProcessedByDict
if
fileProcessedByDict
.
has_key
(
processorName
):
self
.
logger
.
debug
(
'
%s has already been processed by %s
'
%
(
file
,
processorName
))
self
.
logger
.
debug
(
'
%s has already been processed by %s
'
%
(
file
Info
,
processorName
))
continue
self
.
logger
.
debug
(
'
%s is about to process file %s
'
%
(
processorName
,
file
))
self
.
logger
.
debug
(
'
%s is about to process file %s
'
%
(
processorName
,
file
Info
))
try
:
processor
.
processFile
(
file
Path
,
daqPath
,
experiment
)
processor
.
processFile
(
file
Info
)
fileProcessedByDict
[
processorName
]
=
True
file
[
'
processedByDict
'
]
=
fileProcessedByDict
self
.
logger
.
debug
(
'
%s processed file %s
'
%
(
processorName
,
file
))
self
.
logger
.
debug
(
'
%s processed file at path %s
'
%
(
processorName
,
filePath
))
except
Exception
,
ex
:
self
.
logger
.
exception
(
ex
)
self
.
logger
.
debug
(
'
%s processing failed for file %s
'
%
(
processorName
,
file
))
fileProcessingDict
=
file
.
get
(
'
processingDict
'
,
{})
file
[
'
processingDict
'
]
=
fileProcessingDict
self
.
logger
.
debug
(
'
%s processing failed for file
at path
%s
'
%
(
processorName
,
file
Path
))
fileProcessingDict
=
file
Info
.
get
(
'
processingDict
'
,
{})
file
Info
[
'
processingDict
'
]
=
fileProcessingDict
processorDict
=
fileProcessingDict
.
get
(
processorName
,
{})
processorDict
[
'
lastError
'
]
=
ex
fileProcessingDict
[
processorName
]
=
processorDict
processorDict
[
'
lastError
'
]
=
str
(
ex
)
nRetriesLeft
=
processorDict
.
get
(
'
numberOfRetriesLeft
'
,
processor
.
getNumberOfRetries
())
self
.
logger
.
debug
(
'
Number of %s retries left for file %s: %s
'
%
(
processorName
,
file
,
nRetriesLeft
))
self
.
logger
.
debug
(
'
Number of %s retries left for file %s: %s
'
%
(
processorName
,
file
Path
,
nRetriesLeft
))
processorDict
[
'
numberOfRetriesLeft
'
]
=
nRetriesLeft
-
1
if
nRetriesLeft
<=
0
:
self
.
logger
.
debug
(
'
No more %s retries left for file %s
'
%
(
processorName
,
file
))
self
.
unprocessedFileDict
[
filePath
]
=
file
self
.
logger
.
debug
(
'
No more %s retries left for file %s
'
%
(
processorName
,
file
Info
))
self
.
unprocessedFileDict
[
filePath
]
=
file
Info
else
:
retryWaitPeriod
=
processor
.
getRetryWaitPeriodInSeconds
()
self
.
logger
.
debug
(
'
%s will retry processing file %s in %s seconds
'
%
(
processorName
,
file
,
retryWaitPeriod
))
self
.
fileProcessingQueue
.
push
(
file
,
retryWaitPeriod
)
self
.
logger
.
debug
(
'
%s will retry processing file %s in %s seconds
'
%
(
processorName
,
file
Path
,
retryWaitPeriod
))
self
.
fileProcessingQueue
.
push
(
file
Info
,
retryWaitPeriod
)
except
Exception
,
ex
:
self
.
logger
.
exception
(
ex
)
self
.
eventFlag
.
wait
()
self
.
fileProcessingManager
.
waitOnEvent
(
self
.
THREAD_EVENT_TIMEOUT_IN_SECONDS
)
self
.
logger
.
debug
(
'
%s is done
'
%
self
.
getName
())
def
stop
(
self
):
self
.
exitFlag
=
True
...
...
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