From a27e86786ad031eafcbfeb39ffdadf71d80dcfad Mon Sep 17 00:00:00 2001 From: Martin Cech Date: Thu, 26 May 2016 13:14:22 -0400 Subject: [PATCH 1/5] wrap bare str raises with generic Exception() as Pyton 2.7 does not support bare str --- lib/galaxy/external_services/actions.py | 4 +- lib/galaxy/external_services/parameters.py | 2 +- lib/galaxy/external_services/service.py | 2 +- lib/galaxy/forms/forms.py | 2 +- lib/galaxy/model/__init__.py | 10 +-- .../versions/0005_cleanup_datasets_fix.py | 2 +- lib/galaxy/security/__init__.py | 70 +++++++++---------- lib/galaxy/tools/actions/__init__.py | 2 +- .../visualization/data_providers/genome.py | 2 +- .../galaxy/controllers/external_services.py | 2 +- .../webapps/tool_shed/security/__init__.py | 12 ++-- .../tool_dependencies/recipe/step_handler.py | 4 +- .../tool_dependencies/recipe/tag_handler.py | 2 +- lib/tool_shed/repository_types/metadata.py | 2 +- tools/filters/axt_to_lav.py | 7 +- 15 files changed, 62 insertions(+), 63 deletions(-) diff --git a/lib/galaxy/external_services/actions.py b/lib/galaxy/external_services/actions.py index 6a2b6cb646e..c62dadf3e34 100644 --- a/lib/galaxy/external_services/actions.py +++ b/lib/galaxy/external_services/actions.py @@ -80,7 +80,7 @@ class ExternalServiceAction( object ): return handled_results def perform_action( self, param_dict ): - raise 'Abstract Method' + raise Exception( 'Abstract Method' ) class ExternalServiceResult( object ): @@ -90,7 +90,7 @@ class ExternalServiceResult( object ): @property def content( self ): - raise 'Abstract Method' + raise Exception( 'Abstract Method' ) class ExternalServiceWebAPIActionResult( ExternalServiceResult ): diff --git a/lib/galaxy/external_services/parameters.py b/lib/galaxy/external_services/parameters.py index fd7605856b6..4bb9356f1cf 100644 --- a/lib/galaxy/external_services/parameters.py +++ b/lib/galaxy/external_services/parameters.py @@ -21,7 +21,7 @@ class ExternalServiceParameter( object ): self.parent = parent def get_value( self, param_dict ): - raise 'Abstract Method' + raise Exception( 'Abstract Method' ) class ExternalServiceTemplateParameter( ExternalServiceParameter ): diff --git a/lib/galaxy/external_services/service.py b/lib/galaxy/external_services/service.py index ac40f28a130..c05de42480b 100644 --- a/lib/galaxy/external_services/service.py +++ b/lib/galaxy/external_services/service.py @@ -218,7 +218,7 @@ class PopulatedExternalService( object ): elif isinstance( item, ExternalServiceActionsGroup ): item.prepare_actions( param_dict, param_dict, action_list ) else: - raise 'unknown item type found' + raise Exception( 'unknown item type found' ) self.param_dict = param_dict self.actions = action_list diff --git a/lib/galaxy/forms/forms.py b/lib/galaxy/forms/forms.py index 59fb3b2b9de..2907405e5f9 100644 --- a/lib/galaxy/forms/forms.py +++ b/lib/galaxy/forms/forms.py @@ -69,7 +69,7 @@ class FormDefinitionFieldFactory( object ): type = None def __get_stored_field_type( self, **kwds ): - raise 'not implemented' + raise Exception( 'not implemented' ) def new( self, name=None, label=None, required=False, helptext=None, default=None, visible=True, layout=None ): """ diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index eb2d0a24d94..55e9c4dbdff 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -1572,7 +1572,7 @@ class LibraryPermissions( object ): if isinstance( library_item, Library ): self.library = library_item else: - raise "Invalid Library specified: %s" % library_item.__class__.__name__ + raise Exception( "Invalid Library specified: %s" % library_item.__class__.__name__ ) self.role = role @@ -1582,7 +1582,7 @@ class LibraryFolderPermissions( object ): if isinstance( library_item, LibraryFolder ): self.folder = library_item else: - raise "Invalid LibraryFolder specified: %s" % library_item.__class__.__name__ + raise Exception( "Invalid LibraryFolder specified: %s" % library_item.__class__.__name__ ) self.role = role @@ -1592,7 +1592,7 @@ class LibraryDatasetPermissions( object ): if isinstance( library_item, LibraryDataset ): self.library_dataset = library_item else: - raise "Invalid LibraryDataset specified: %s" % library_item.__class__.__name__ + raise Exception( "Invalid LibraryDataset specified: %s" % library_item.__class__.__name__ ) self.role = role @@ -1602,7 +1602,7 @@ class LibraryDatasetDatasetAssociationPermissions( object ): if isinstance( library_item, LibraryDatasetDatasetAssociation ): self.library_dataset_dataset_association = library_item else: - raise "Invalid LibraryDatasetDatasetAssociation specified: %s" % library_item.__class__.__name__ + raise Exception( "Invalid LibraryDatasetDatasetAssociation specified: %s" % library_item.__class__.__name__ ) self.role = role @@ -2079,7 +2079,7 @@ class DatasetInstance( object ): return fake_hda def clear_associated_files( self, metadata_safe=False, purge=False ): - raise 'Unimplemented' + raise Exception( "Unimplemented" ) def get_child_by_designation(self, designation): for child in self.children: diff --git a/lib/galaxy/model/migrate/versions/0005_cleanup_datasets_fix.py b/lib/galaxy/model/migrate/versions/0005_cleanup_datasets_fix.py index 65f86d6d3a7..2ee8fe64db1 100644 --- a/lib/galaxy/model/migrate/versions/0005_cleanup_datasets_fix.py +++ b/lib/galaxy/model/migrate/versions/0005_cleanup_datasets_fix.py @@ -274,7 +274,7 @@ class DatasetInstance( object ): return valid def clear_associated_files( self, metadata_safe=False, purge=False ): - raise 'Unimplemented' + raise Exception( 'Unimplemented' ) def get_child_by_designation(self, designation): for child in self.children: diff --git a/lib/galaxy/security/__init__.py b/lib/galaxy/security/__init__.py index 3f2b6605c44..722d3c4723d 100644 --- a/lib/galaxy/security/__init__.py +++ b/lib/galaxy/security/__init__.py @@ -48,97 +48,97 @@ class RBACAgent: return self.permitted_actions.__dict__.values() def get_item_actions( self, action, item ): - raise 'No valid method of retrieving action (%s) for item %s.' % ( action, item ) + raise Exception( 'No valid method of retrieving action (%s) for item %s.' % ( action, item ) ) def guess_derived_permissions_for_datasets( self, datasets=[] ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def can_access_dataset( self, roles, dataset ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def can_manage_dataset( self, roles, dataset ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def can_access_library( self, roles, library ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def can_add_library_item( self, roles, item ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def can_modify_library_item( self, roles, item ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def can_manage_library_item( self, roles, item ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def associate_components( self, **kwd ): - raise 'No valid method of associating provided components: %s' % kwd + raise Exception( 'No valid method of associating provided components: %s' % kwd ) def create_private_user_role( self, user ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def get_private_user_role( self, user ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def get_accessible_request_types( self, trans, user ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def user_set_default_permissions( self, user, permissions={}, history=False, dataset=False ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def history_set_default_permissions( self, history, permissions=None, dataset=False, bypass_manage_permission=False ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def set_all_dataset_permissions( self, dataset, permissions, new=False ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def set_dataset_permission( self, dataset, permission ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def set_all_library_permissions( self, trans, dataset, permissions ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def set_library_item_permission( self, library_item, permission ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def library_is_public( self, library ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def make_library_public( self, library ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def get_accessible_libraries( self, trans, user ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def get_permitted_libraries( self, trans, user, actions ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def folder_is_public( self, library ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def make_folder_public( self, folder, count=0 ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def dataset_is_public( self, dataset ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def make_dataset_public( self, dataset ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def get_permissions( self, library_dataset ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def get_all_roles( self, trans, cntrller ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def get_legitimate_roles( self, trans, item, cntrller ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def derive_roles_from_access( self, trans, item_id, cntrller, library=False, **kwd ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def get_component_associations( self, **kwd ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def components_are_associated( self, **kwd ): return bool( self.get_component_associations( **kwd ) ) @@ -736,7 +736,7 @@ class GalaxyRBACAgent( RBACAgent ): if 'action' in kwd: if 'dataset' in kwd and 'role' in kwd: return self.associate_action_dataset_role( kwd['action'], kwd['dataset'], kwd['role'] ) - raise 'No valid method of associating provided components: %s' % kwd + raise Exception( 'No valid method of associating provided components: %s' % kwd ) def associate_user_group( self, user, group ): assoc = self.model.UserGroupAssociation( user, group ) @@ -1300,7 +1300,7 @@ class GalaxyRBACAgent( RBACAgent ): self.sa_session.add( lp ) self.sa_session.flush() else: - raise 'Invalid class (%s) specified for target_library_item (%s)' % \ + raise Exception( 'Invalid class (%s) specified for target_library_item (%s)' % \ ) ( target_library_item.__class__, target_library_item.__class__.__name__ ) def get_permitted_libraries( self, trans, user, actions ): @@ -1435,7 +1435,7 @@ class GalaxyRBACAgent( RBACAgent ): elif 'group' in kwd: if 'role' in kwd: return self.sa_session.query( self.model.GroupRoleAssociation ).filter_by( role_id=kwd['role'].id, group_id=kwd['group'].id ).first() - raise 'No valid method of associating provided components: %s' % kwd + raise Exception( 'No valid method of associating provided components: %s' % kwd ) def check_folder_contents( self, user, roles, folder, hidden_folder_ids='' ): """ @@ -1567,7 +1567,7 @@ class HostAgent( RBACAgent ): log.debug( 'Allowing access to private dataset with hda: %i. Remote server is: %s.' % ( hda.id, server ) ) return True else: - raise 'The dataset access permission is the only valid permission in the host security agent.' + raise Exception( 'The dataset access permission is the only valid permission in the host security agent.' ) def set_dataset_permissions( self, hda, user, site ): hdadaa = self.sa_session.query( self.model.HistoryDatasetAssociationDisplayAtAuthorization ) \ diff --git a/lib/galaxy/tools/actions/__init__.py b/lib/galaxy/tools/actions/__init__.py index 03b5d40ff38..aedb8e7409b 100644 --- a/lib/galaxy/tools/actions/__init__.py +++ b/lib/galaxy/tools/actions/__init__.py @@ -78,7 +78,7 @@ class DefaultToolAction( object ): data = new_data if not trans.app.security_agent.can_access_dataset( current_user_roles, data.dataset ): - raise "User does not have permission to use a dataset (%s) provided for input." % data.id + raise Exception( "User does not have permission to use a dataset (%s) provided for input." % data.id ) return data if isinstance( input, DataToolParameter ): if isinstance( value, list ): diff --git a/lib/galaxy/visualization/data_providers/genome.py b/lib/galaxy/visualization/data_providers/genome.py index 81b69f167a7..f403afe57dc 100644 --- a/lib/galaxy/visualization/data_providers/genome.py +++ b/lib/galaxy/visualization/data_providers/genome.py @@ -1483,7 +1483,7 @@ class ENCODEPeakDataProvider( GenomeDataProvider ): """ def get_iterator( self, data_file, chrom, start, end, **kwargs ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def process_data( self, iterator, start_val=0, max_vals=None, **kwargs ): """ diff --git a/lib/galaxy/webapps/galaxy/controllers/external_services.py b/lib/galaxy/webapps/galaxy/controllers/external_services.py index 51917ddde38..638d52f80a2 100644 --- a/lib/galaxy/webapps/galaxy/controllers/external_services.py +++ b/lib/galaxy/webapps/galaxy/controllers/external_services.py @@ -24,4 +24,4 @@ class ExternalServiceController( BaseUIController ): results = populated_action.handle_results( trans ) return results else: - raise 'unknown item class type' + raise Exception( 'unknown item class type' ) diff --git a/lib/galaxy/webapps/tool_shed/security/__init__.py b/lib/galaxy/webapps/tool_shed/security/__init__.py index 4a5bba94303..46603ab2359 100644 --- a/lib/galaxy/webapps/tool_shed/security/__init__.py +++ b/lib/galaxy/webapps/tool_shed/security/__init__.py @@ -22,10 +22,10 @@ class RBACAgent: permitted_actions = Bunch() def associate_components( self, **kwd ): - raise 'No valid method of associating provided components: %s' % kwd + raise Exception( 'No valid method of associating provided components: %s' % kwd ) def associate_user_role( self, user, role ): - raise 'No valid method of associating a user with a role' + raise Exception( 'No valid method of associating a user with a role' ) def convert_permitted_action_strings( self, permitted_action_strings ): """ @@ -35,7 +35,7 @@ class RBACAgent: return filter( lambda x: x is not None, [ self.permitted_actions.get( action_string ) for action_string in permitted_action_strings ] ) def create_private_user_role( self, user ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) def get_action( self, name, default=None ): """Get a permitted action by its dict key or action name""" @@ -49,10 +49,10 @@ class RBACAgent: return self.permitted_actions.__dict__.values() def get_item_actions( self, action, item ): - raise 'No valid method of retrieving action (%s) for item %s.' % ( action, item ) + raise Exception( 'No valid method of retrieving action (%s) for item %s.' % ( action, item ) ) def get_private_user_role( self, user ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) class CommunityRBACAgent( RBACAgent ): @@ -93,7 +93,7 @@ class CommunityRBACAgent( RBACAgent ): return self.associate_group_role( kwd['group'], kwd['role'] ) elif 'repository' in kwd: return self.associate_repository_category( kwd[ 'repository' ], kwd[ 'category' ] ) - raise 'No valid method of associating provided components: %s' % kwd + raise Exception( 'No valid method of associating provided components: %s' % kwd ) def associate_group_role( self, group, role ): assoc = self.model.GroupRoleAssociation( group, role ) diff --git a/lib/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler.py b/lib/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler.py index fcd9cd40f62..e225c4a5b8f 100755 --- a/lib/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler.py +++ b/lib/tool_shed/galaxy_install/tool_dependencies/recipe/step_handler.py @@ -239,10 +239,10 @@ class RecipeStep( object ): def execute_step( self, tool_dependency, package_name, actions, action_dict, filtered_actions, env_file_builder, install_environment, work_dir, current_dir=None, initial_download=False ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method") def prepare_step( self, tool_dependency, action_elem, action_dict, install_environment, is_binary_download ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) class AssertDirectoryExecutable( RecipeStep ): diff --git a/lib/tool_shed/galaxy_install/tool_dependencies/recipe/tag_handler.py b/lib/tool_shed/galaxy_install/tool_dependencies/recipe/tag_handler.py index d505325a8be..06c6566c7e5 100644 --- a/lib/tool_shed/galaxy_install/tool_dependencies/recipe/tag_handler.py +++ b/lib/tool_shed/galaxy_install/tool_dependencies/recipe/tag_handler.py @@ -22,7 +22,7 @@ class RecipeTag( object ): def process_tag_set( self, tool_shed_repository, tool_dependency, package_elem, package_name, package_version, from_tool_migration_manager=False, tool_dependency_db_records=None ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) class SyncDatabase( object ): diff --git a/lib/tool_shed/repository_types/metadata.py b/lib/tool_shed/repository_types/metadata.py index b3e876437bd..be011aa1772 100644 --- a/lib/tool_shed/repository_types/metadata.py +++ b/lib/tool_shed/repository_types/metadata.py @@ -16,7 +16,7 @@ class Metadata( object ): return repo.changelog def is_valid_for_type( self, app, repository, revisions_to_check=None ): - raise "Unimplemented Method" + raise Exception( "Unimplemented Method" ) class TipOnly( Metadata ): diff --git a/tools/filters/axt_to_lav.py b/tools/filters/axt_to_lav.py index 9d0ad8b0ba6..8709c26b314 100644 --- a/tools/filters/axt_to_lav.py +++ b/tools/filters/axt_to_lav.py @@ -156,17 +156,16 @@ def read_lengths(fileName): fields = line.split() if len(fields) != 2: - raise "bad lengths line (%s:%d): %s" % (fileName, lineNumber, line) + raise Exception( "bad lengths line (%s:%d): %s" % (fileName, lineNumber, line) ) chrom = fields[0] try: length = int(fields[1]) except: - raise "bad lengths line (%s:%d): %s" % (fileName, lineNumber, line) + raise Exception( "bad lengths line (%s:%d): %s" % (fileName, lineNumber, line) ) if chrom in chromToLength: - raise "%s appears more than once (%s:%d): %s" \ - % (chrom, fileName, lineNumber) + raise Exception( "%s appears more than once (%s:%d): %s" % (chrom, fileName, lineNumber) ) chromToLength[chrom] = length From fe64a8198bca75f2e535efc7c3813d24810904ab Mon Sep 17 00:00:00 2001 From: Martin Cech Date: Thu, 26 May 2016 13:37:02 -0400 Subject: [PATCH 2/5] fix the mess made with mass edit --- lib/galaxy/security/__init__.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/security/__init__.py b/lib/galaxy/security/__init__.py index 722d3c4723d..9b5b5dac33b 100644 --- a/lib/galaxy/security/__init__.py +++ b/lib/galaxy/security/__init__.py @@ -1300,8 +1300,8 @@ class GalaxyRBACAgent( RBACAgent ): self.sa_session.add( lp ) self.sa_session.flush() else: - raise Exception( 'Invalid class (%s) specified for target_library_item (%s)' % \ ) - ( target_library_item.__class__, target_library_item.__class__.__name__ ) + raise Exception( 'Invalid class (%s) specified for target_library_item (%s)' % + ( target_library_item.__class__, target_library_item.__class__.__name__ ) ) def get_permitted_libraries( self, trans, user, actions ): """ From 214e757d81623e9c12d171f3dcfc516c7dcc5e32 Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Tue, 31 May 2016 11:42:36 -0400 Subject: [PATCH 3/5] Only scan the last 16 MB of a job's stderr for slurm memory warning messages. --- lib/galaxy/jobs/runners/slurm.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/galaxy/jobs/runners/slurm.py b/lib/galaxy/jobs/runners/slurm.py index 7349586ec8c..bab11589341 100644 --- a/lib/galaxy/jobs/runners/slurm.py +++ b/lib/galaxy/jobs/runners/slurm.py @@ -2,6 +2,7 @@ SLURM job control via the DRMAA API. """ +import os import time import logging import subprocess @@ -16,6 +17,7 @@ __all__ = [ 'SlurmJobRunner' ] SLURM_MEMORY_LIMIT_EXCEEDED_MSG = 'slurmstepd: error: Exceeded job memory limit' SLURM_MEMORY_LIMIT_EXCEEDED_PARTIAL_WARNINGS = [': Exceeded job memory limit at some point.', ': Exceeded step memory limit at some point.'] +SLURM_MEMORY_LIMIT_SCAN_SIZE = 16 * 1024 * 1024 # 16MB class SlurmJobRunner( DRMAAJobRunner ): @@ -88,6 +90,8 @@ class SlurmJobRunner( DRMAAJobRunner ): return if drmaa_state == self.drmaa_job_states.DONE: with open(ajs.error_file, 'r+') as f: + if os.path.getsize(ajs.error_file) > SLURM_MEMORY_LIMIT_SCAN_SIZE: + f.seek(-SLURM_MEMORY_LIMIT_SCAN_SIZE, os.SEEK_END) lines = f.readlines() f.seek(0) for line in lines: From dcb28e095012fef3be769f677fa572f13d4ed88a Mon Sep 17 00:00:00 2001 From: Nate Coraor Date: Tue, 31 May 2016 11:58:57 -0400 Subject: [PATCH 4/5] Fix linting error --- lib/galaxy/jobs/runners/slurm.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/galaxy/jobs/runners/slurm.py b/lib/galaxy/jobs/runners/slurm.py index bab11589341..834e289b43b 100644 --- a/lib/galaxy/jobs/runners/slurm.py +++ b/lib/galaxy/jobs/runners/slurm.py @@ -17,7 +17,7 @@ __all__ = [ 'SlurmJobRunner' ] SLURM_MEMORY_LIMIT_EXCEEDED_MSG = 'slurmstepd: error: Exceeded job memory limit' SLURM_MEMORY_LIMIT_EXCEEDED_PARTIAL_WARNINGS = [': Exceeded job memory limit at some point.', ': Exceeded step memory limit at some point.'] -SLURM_MEMORY_LIMIT_SCAN_SIZE = 16 * 1024 * 1024 # 16MB +SLURM_MEMORY_LIMIT_SCAN_SIZE = 16 * 1024 * 1024 # 16MB class SlurmJobRunner( DRMAAJobRunner ): From 7cb527ac595591c99401436757168b366f86a526 Mon Sep 17 00:00:00 2001 From: Nicola Soranzo Date: Thu, 2 Jun 2016 15:00:10 +0100 Subject: [PATCH 5/5] Overwrite the correct part of stderr - Skip partial line - Seek back to the correct position after readlines() - Use the same approach in __check_memory_limit() --- lib/galaxy/jobs/runners/slurm.py | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/lib/galaxy/jobs/runners/slurm.py b/lib/galaxy/jobs/runners/slurm.py index 834e289b43b..a7addb0412b 100644 --- a/lib/galaxy/jobs/runners/slurm.py +++ b/lib/galaxy/jobs/runners/slurm.py @@ -92,8 +92,10 @@ class SlurmJobRunner( DRMAAJobRunner ): with open(ajs.error_file, 'r+') as f: if os.path.getsize(ajs.error_file) > SLURM_MEMORY_LIMIT_SCAN_SIZE: f.seek(-SLURM_MEMORY_LIMIT_SCAN_SIZE, os.SEEK_END) + f.readline() + pos = f.tell() lines = f.readlines() - f.seek(0) + f.seek(pos) for line in lines: stripped_line = line.strip() if any([_ in stripped_line for _ in SLURM_MEMORY_LIMIT_EXCEEDED_PARTIAL_WARNINGS]): @@ -114,21 +116,12 @@ class SlurmJobRunner( DRMAAJobRunner ): try: log.debug( 'Checking %s for exceeded memory message from slurm', efile_path ) with open( efile_path ) as f: - pos = 2 - bof = False - while pos < 2048: - try: - f.seek(-pos, 2) - pos += 1 - except: - f.seek(-pos + 1, 2) - bof = True - - if (bof or f.read(1) == '\n') and f.readline().strip() == SLURM_MEMORY_LIMIT_EXCEEDED_MSG: + if os.path.getsize(efile_path) > 2048: + f.seek(-2048, os.SEEK_END) + f.readline() + for line in f.readlines(): + if line.strip() == SLURM_MEMORY_LIMIT_EXCEEDED_MSG: return True - - if bof: - break except: log.exception('Error reading end of %s:', efile_path)