<commit_before># Copyright (C) 2007-2011 <NAME>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
"""
Represents a batch of enqueued actions.
"""
from Exscript.util.event import Event

class Task(object):
    """
    Represents a batch of running actions.
    """
    def __init__(self, queue):
        self.done_event       = Event()
        self.queue            = queue
        self.action_hash_list = []
        self.completed        = 0

    def _on_action_done(self, action):
        self.completed += 1
        if self.is_completed():
            self.done_event()

    def is_completed(self):
        """
        Returns True if all actions in the task are completed, returns
        False otherwise.

        @rtype:  bool
        @return: Whether the task is completed.
        """
        return self.completed == len(self.action_hash_list)

    def wait(self):
        """
        Waits until all actions in the task have completed.
        Does not use any polling.
        """
        for thehash in self.action_hash_list:
            self.queue.wait_for(thehash)

    def add_action(self, action):
        """
        Adds a new action to the task.

        @type  action: Action
        @param action: The action to be added.
        """
        self.action_hash_list.append(action.__hash__())
        action.aborted_event.listen(self._on_action_done)
        action.succeeded_event.listen(self._on_action_done)<commit_msg>Exscript.Task: replace action hash list() by a set().<commit_after># Copyright (C) 2007-2011 <NAME>.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2, as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
"""
Represents a batch of enqueued actions.
"""
from Exscript.util.event import Event

class Task(object):
    """
    Represents a batch of running actions.
    """
    def __init__(self, queue):
        self.done_event    = Event()
        self.queue         = queue
        self.action_hashes = set()
        self.completed     = 0

    def _on_action_done(self, action):
        self.completed += 1
        if self.is_completed():
            self.done_event()

    def is_completed(self):
        """
        Returns True if all actions in the task are completed, returns
        False otherwise.

        @rtype:  bool
        @return: Whether the task is completed.
        """
        return self.completed == len(self.action_hashes)

    def wait(self):
        """
        Waits until all actions in the task have completed.
        Does not use any polling.
        """
        for thehash in self.action_hashes:
            self.queue.wait_for(thehash)

    def add_action(self, action):
        """
        Adds a new action to the task.

        @type  action: Action
        @param action: The action to be added.
        """
        self.action_hashes.add(action.__hash__())
        action.aborted_event.listen(self._on_action_done)
        action.succeeded_event.listen(self._on_action_done)
{'fraction_non_alphanumeric': 0.08069659063036547, 'fraction_numerical': 0.01226391954868776, 'mean_word_length': 2.5064488392089426, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3997081', 'n_tokens_mistral': 1155, 'n_tokens_neox': 1085, 'n_words': 433}