Skip to content
Permalink
Browse files
Harden everything up
And finally fix a racy condition which has been plaguing me for
ages
  • Loading branch information
nyalldawson committed Dec 5, 2016
1 parent 32a9e1e commit 14b6b3f6eebbfea5f8ea3cef7b806ccfdbf3c9c8
Showing with 286 additions and 113 deletions.
  1. +14 −2 python/core/__init__.py
  2. +0 −3 python/core/qgstaskmanager.sip
  3. +158 −42 src/core/qgstaskmanager.cpp
  4. +17 −5 src/core/qgstaskmanager.h
  5. +26 −25 src/gui/qgstaskmanagerwidget.cpp
  6. +1 −1 src/gui/qgstaskmanagerwidget.h
  7. +70 −35 tests/src/core/testqgstaskmanager.cpp
@@ -29,6 +29,8 @@

import inspect
import string
import types
import functools
from qgis._core import *

# Boolean evaluation of QgsGeometry
@@ -185,14 +187,24 @@ def __exit__(self, ex_type, ex_value, traceback):
return False


def copy_func(f):
"""Based on http://stackoverflow.com/a/6528148/190597 (Glenn Maynard)"""
g = types.FunctionType(f.__code__, f.__globals__, name=f.__name__,
argdefs=f.__defaults__,
closure=f.__closure__)
g = functools.update_wrapper(g, f)
g.__kwdefaults__ = f.__kwdefaults__
return g


class QgsTaskWrapper(QgsTask):

def __init__(self, description, function, on_finished, *args, **kwargs):
QgsTask.__init__(self, description)
self.args = args
self.kwargs = kwargs
self.function = function
self.on_finished = on_finished
self.function = copy_func(function)
self.on_finished = copy_func(on_finished)
self.returned_values = None
self.exception = None

@@ -353,9 +353,6 @@ class QgsTaskManager : QObject
//! @note not available in Python bindings
//QSet< long > dependencies( long taskId ) const;

//! Will return true if the specified task has circular dependencies
bool hasCircularDependencies( long taskId ) const;

/** Sets a list of layers on which as task is dependent. The task will automatically
* be cancelled if any of these layers are above to be removed.
* @param taskId task ID
Loading

0 comments on commit 14b6b3f

Please sign in to comment.