Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
erp5
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Hardik Juneja
erp5
Commits
5544b59b
Commit
5544b59b
authored
Dec 08, 2016
by
Loic Esteve
Committed by
Hardik Juneja
Jan 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Move class definitions inside ENABLE_JOBLIB block
parent
bd51d473
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
29 deletions
+29
-29
product/CMFActivity/ActivityJoblibBackend.py
product/CMFActivity/ActivityJoblibBackend.py
+29
-29
No files found.
product/CMFActivity/ActivityJoblibBackend.py
View file @
5544b59b
...
...
@@ -43,38 +43,38 @@ except ImportError:
LOG
(
"CMFActivityBackend"
,
WARNING
,
"CLASS NOT LOADED!!!"
)
ENABLE_JOBLIB
=
False
class
MySafeFunction
(
SafeFunction
):
"""Wrapper around a SafeFunction that catches any exception
if
ENABLE_JOBLIB
:
class
MySafeFunction
(
SafeFunction
):
"""Wrapper around a SafeFunction that catches any exception
The exception can be handled in CMFActivityResult.get
"""
def
__call__
(
self
,
*
args
,
**
kwargs
):
try
:
return
super
(
MySafeFunction
,
self
).
__call__
(
*
args
,
**
kwargs
)
except
Exception
as
exc
:
return
exc
The exception can be handled in CMFActivityResult.get
"""
def
__call__
(
self
,
*
args
,
**
kwargs
):
try
:
return
super
(
MySafeFunction
,
self
).
__call__
(
*
args
,
**
kwargs
)
except
Exception
as
exc
:
return
exc
class
CMFActivityResult
(
object
):
def
__init__
(
self
,
active_process
,
callback
):
self
.
active_process
=
active_process
self
.
callback
=
callback
def
get
(
self
,
timeout
=
None
):
while
not
self
.
active_process
.
getResultList
():
time
.
sleep
(
1
)
if
timeout
is
not
None
:
timeout
-=
1
if
timeout
<
0
:
raise
RuntimeError
(
'Timeout reached'
)
transaction
.
commit
()
result
=
self
.
active_process
.
getResultList
()[
0
].
result
# TODO raise before or after the callback?
if
isinstance
(
result
,
Exception
):
raise
result
if
self
.
callback
is
not
None
:
self
.
callback
(
result
)
return
result
class
CMFActivityResult
(
object
):
def
__init__
(
self
,
active_process
,
callback
):
self
.
active_process
=
active_process
self
.
callback
=
callback
def
get
(
self
,
timeout
=
None
):
while
not
self
.
active_process
.
getResultList
():
time
.
sleep
(
1
)
if
timeout
is
not
None
:
timeout
-=
1
if
timeout
<
0
:
raise
RuntimeError
(
'Timeout reached'
)
transaction
.
commit
()
result
=
self
.
active_process
.
getResultList
()[
0
].
result
# TODO raise before or after the callback?
if
isinstance
(
result
,
Exception
):
raise
result
if
self
.
callback
is
not
None
:
self
.
callback
(
result
)
return
result
if
ENABLE_JOBLIB
:
class
CMFActivityBackend
(
ParallelBackendBase
):
def
__init__
(
self
,
*
args
,
**
kwargs
):
self
.
zope_context
=
kwargs
[
'zope_context'
]
...
...
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