Logo Search packages:      
Sourcecode: python-biopython version File versions  Download package


# Copyright 2007 by Tiago Antao <tiagoantao@gmail.com>.  All rights reserved.
# This code is part of the Biopython distribution and governed by its
# license.  Please see the LICENSE file that should have been included
# as part of this package.

Support for asynchronous execution.


import os
import thread

00016 class Async:
    '''Abstract Asynchronous execution class.

       This is the top abstract class.
       Concrete classes must implement the _run_program method.

00023     def __init__(self):
        '''Async constructor.

           Initializes the queues, among other things.
           Of notice, is the access_ds lock for controlling exclusive
               access to this object.
        self.running = {}
        self.waiting = []
        self.done = {}
        self.id = 0
        self.hooks = {}
        self.access_ds = thread.allocate_lock()

00037     def run_program(self, program, parameters, input_files):
        '''Runs a program.
           Real _run_program to be implemented by concrete classes.

           program String identifying program.
           parameters List of String parameters.
           input_files Hash of Input file descriptors.

           Task Id.

           The input_files hash key is the path that is passed
           to the program. It should always be relative.
           Value is a stream.
        if program in self.hooks:
            self.id += 1
            id = self.id
            self._run_program(id, self.hooks[program], parameters, input_files)
            return id

00062     def get_result(self, id):
        ''' Returns the results for a certain Id, the info for that Id is

            id Id of the task.

            (return_code, output_files) return code and file access

            The output_files hash key is a relative file name, and the value a
            output stream.
        if id in self.done:
            returnCode, fileObject = done[id]
            del done[id]
            return None

00085 class FileRetriever:
    '''An Abstract Support class to retrieve files.

    def __init__(self):

00092     def get_File_list(self):
        '''Returns the list of available files.
        return self.file_list

    def get_file(self, name):
        raise NotImplementedError('Abstract method')

00100 class DirectoryRetriever(FileRetriever):
    '''Retrieves a directory content.

    def __init__(self, directory):
        self.directory = directory
        walk_list = os.walk(directory)
        for dir, dir_list, file_list in walk_list:
            for file in file_list:

    def get_file(self, name):
        return open(self.directory + os.sep + name)

Generated by  Doxygen 1.6.0   Back to index