Package csb :: Package bio :: Package io :: Module wwpdb :: Class AsyncStructureParser

[frames] | no frames]

# Class AsyncStructureParser

source code

    object --+
             |
            AsyncStructureParser

Wraps StructureParser in an asynchronous call. Since a new process is started by Python internally (as opposed to only starting a new thread), this makes the parser slower, but provides a way to set a parse timeout limit.

If initialized with more than one worker, supports parallel parsing through the `self.parse_async` method.

Instance Methods

__init__(self, workers=1) x.__init__(...) initializes x; see help(type(x)) for signature | source code

list

parse_async(self, structure_files, timeout, model=None, parser=<class 'csb.bio.io.wwpdb.RegularStructureParser'>) Call `self.parse_structure` for a list of structure files simultaneously. | source code

csb.structure.Structure

parse_structure(self, structure_file, timeout, model=None, parser=<class 'csb.bio.io.wwpdb.RegularStructureParser'>) Call StructureParser.parse_structure() in a separate process and return the output. | source code

Inherited from `object`: `__delattr__`, `__format__`, `__getattribute__`, `__hash__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__repr__`, `__setattr__`, `__sizeof__`, `__str__`, `__subclasshook__`

Properties
Inherited from `object`: `__class__`

Method Details

### __init__(self, workers=1)
(Constructor)

source code

x.__init__(...) initializes x; see help(type(x)) for signature

Parameters:
  - `workers` (int) - number of worker threads (1 by default)
Overrides: object.__init__
  (inherited documentation)

### parse_async(self, structure_files, timeout, model=None, parser=<class 'csb.bio.io.wwpdb.RegularStructureParser'>)

source code

Call `self.parse_structure` for a list of structure files simultaneously. The actual degree of parallelism will depend on the number of workers specified while constructing the parser object.

Parameters:
  - `structure_files` (tuple of str) - a list of structure files
  - `timeout` (int) - raise multiprocessing.TimeoutError if `timeout` seconds elapse before the parser completes its job
  - `parser` (type) - any implementing AbstractStructureParser class
Returns: list
  a list of AsyncParseResult objects

Note: Don't be tempted to pass a large list of structures to this method. Every time a `TimeoutError` is encountered, the corresponding worker process in the pool will hang until the process terminates on its own. During that time, this worker is unusable. If a sufficiently high number of timeouts occur, the whole pool of workers will be unsable. At the end of the method however a pool cleanup is performed and any unusable workers are 'reactivated'. However, that only happens at the end of `parse_async`.

### parse_structure(self, structure_file, timeout, model=None, parser=<class 'csb.bio.io.wwpdb.RegularStructureParser'>)

source code

Call StructureParser.parse_structure() in a separate process and return the output. Raise TimeoutError if the parser does not respond within `timeout` seconds.

Parameters:
  - `structure_file` (str) - structure file to parse
  - `timeout` (int) - raise multiprocessing.TimeoutError if `timeout` seconds elapse before the parser completes its job
  - `parser` (type) - any implementing AbstractStructureParser class
Returns: csb.structure.Structure
  parsed structure