How to use the pydra.cluster.tasks.Task function in pydra

To help you get started, we’ve selected a few pydra examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kreneskyp / Pydra / examples / demo / fail.py View on Github external
from pydra.cluster.tasks import Task

class Fail(Task):
    #syntax fail
    foo = bar
    
    def __init__(self):
        fake + die
github kreneskyp / Pydra / examples / demo / fail_tasks.py View on Github external
GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Pydra.  If not, see .
"""


from pydra.cluster.tasks import Task, TaskContainer, ParallelTask

import time

import logging
logger = logging.getLogger('root')


class FailTask(Task):
    """
    Task that always throws an exception
    """

    description = 'I sleep for 5 seconds, then I intentionally throw an exeption'

    def __init__(self, msg='Demo Task'):
        Task.__init__(self, msg)

    def work(self, **kwargs):
        time.sleep(5)
        logger.debug('FAILING!!')
        #failing intentionally
        i_dont_exist[0/0]
        logger.debug('FAILed?')
github kreneskyp / Pydra / examples / demo / demo_task.py View on Github external
import logging
logger = logging.getLogger('root')
logger.setLevel(logging.DEBUG)

from django import forms
class TestTaskInput(forms.Form):
    """
    Form object used to render an interface that captures input
    for TestTask.
    """
    start = forms.IntegerField(initial='0', help_text='Start counting with this number')
    end   = forms.IntegerField(initial='5', help_text='End counting with this number')


class TestTask(Task):
    """
    Simple Task used for testing

    This task increments a counter and then sleeps 5 seconds.  it will repeat this 5 times.
    The counter is returned in a list of arguments so that the data can be passed to another task
    if this task is used in a sequence of tasks
    """
    count = 0
    stop = 5
    description = 'A Demo task that counts to 5, taking a nap after each number'
    form = TestTaskInput

    def __init__(self, msg='Demo Task', *args, **kwargs):
        Task.__init__(self, msg)

    def work(self, **kwargs):
github kreneskyp / Pydra / pydra / cluster / tasks / parallel_task.py View on Github external
You should have received a copy of the GNU General Public License
    along with Pydra.  If not, see .
"""

from __future__ import with_statement
from threading import Thread, RLock
from twisted.internet import reactor, threads

from pydra.cluster.tasks import Task, TaskNotFoundException, STATUS_CANCELLED, STATUS_CANCELLED,\
    STATUS_FAILED,STATUS_STOPPED,STATUS_RUNNING,STATUS_PAUSED,STATUS_COMPLETE

import logging
logger = logging.getLogger('root')

class ParallelTask(Task):
    """
    ParallelTask - is a task that can be broken into discrete work units
    """
    _lock = None                # general lock
    _data = None                # list of data for this task
    _data_in_progress = {}      # workunits of data
    _workunit_count = 0         # count of workunits handed out.  This is used to identify transactions
    _workunit_total = 0
    _workunit_completed = 0     # count of workunits handed out.  This is used to identify transactions
    subtask_key = None          # cached key from subtask

    def __init__(self, msg=None):
        Task.__init__(self, msg)
        self._lock = RLock()
        self.subtask = None              # subtask that is parallelized
        self.__subtask_class = None      # class of subtask
github kreneskyp / Pydra / examples / demo / demo_task.py View on Github external
"""

from pydra.cluster.tasks import Task, TaskContainer, ParallelTask
import time

from django import forms
class TestTaskInput(forms.Form):
    """
    Form object used to render an interface that captures input
    for TestTask.
    """
    start = forms.IntegerField(initial='0', help_text='Start counting with this number')
    end   = forms.IntegerField(initial='5', help_text='End counting with this number')


class TestTask(Task):
    """
    Simple Task used for testing

    This task increments a counter and then sleeps 5 seconds.  it will repeat this 5 times.
    The counter is returned in a list of arguments so that the data can be passed to another task
    if this task is used in a sequence of tasks
    """
    count = 0
    stop = 5
    description = 'A Demo task that counts to 5, taking a nap after each number'
    form = TestTaskInput

    def __init__(self, msg='Demo Task'):
        Task.__init__(self, msg)

    def work(self, **kwargs):
github kreneskyp / Pydra / pydra / cluster / tasks / parallel_task.py View on Github external
You should have received a copy of the GNU General Public License
    along with Pydra.  If not, see .
"""

from __future__ import with_statement

import logging
from threading import Thread, RLock
from twisted.internet import reactor, threads

from pydra.cluster.tasks import Task, TaskNotFoundException, STATUS_CANCELLED,\
    STATUS_FAILED,STATUS_STOPPED,STATUS_RUNNING,STATUS_PAUSED,STATUS_COMPLETE
from pydra.cluster.tasks.datasource import unpack, validate
from pydra.util.key import thaw

class ParallelTask(Task):
    """
    ParallelTask - is a task that can be broken into discrete work units
    """
    _data_in_progress = {}      # workunits of data
    _workunit_count = 1         # count of workunits handed out.  This is used to identify transactions
    _workunit_total = 0
    _workunit_completed = 0     # count of workunits handed out.  This is used to identify transactions
    subtask_key = None          # cached key from subtask

    datasource = None
    """The datasource description."""
    slicer = None

    def __init__(self, msg=None):
        Task.__init__(self, msg)
        self._lock = RLock()             # general lock
github kreneskyp / Pydra / pydra / cluster / tasks / parallel_task.py View on Github external
def __getattribute__(self, key):
        """
        Overridden to lazy instantiate subtask when requested
        """
        if key == 'subtask':
            if not self.__dict__['subtask']:
                subtask = self.__subtask_class(*self.__subtask_args, \
                                                    **self.__subtask_kwargs)
                self.subtask = subtask
            return self.__dict__['subtask']
        return Task.__getattribute__(self, key)