Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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 14b6b3f
Show file tree
Hide file tree
Showing 7 changed files with 286 additions and 113 deletions.
16 changes: 14 additions & 2 deletions python/core/__init__.py
Expand Up @@ -29,6 +29,8 @@

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

# Boolean evaluation of QgsGeometry
Expand Down Expand Up @@ -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

Expand Down
3 changes: 0 additions & 3 deletions python/core/qgstaskmanager.sip
Expand Up @@ -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
Expand Down

0 comments on commit 14b6b3f

Please sign in to comment.