mirror of
				https://github.com/python/cpython.git
				synced 2025-11-03 23:21:29 +00:00 
			
		
		
		
	you can't get resource.error if you can't import resource
This commit is contained in:
		
							parent
							
								
									13859bfedc
								
							
						
					
					
						commit
						964561bb7c
					
				
					 1 changed files with 17 additions and 11 deletions
				
			
		| 
						 | 
				
			
			@ -18,6 +18,12 @@
 | 
			
		|||
except ImportError:
 | 
			
		||||
    gc = None
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
    import resource
 | 
			
		||||
except ImportError:
 | 
			
		||||
    resource = None
 | 
			
		||||
 | 
			
		||||
mswindows = (sys.platform == "win32")
 | 
			
		||||
 | 
			
		||||
#
 | 
			
		||||
| 
						 | 
				
			
			@ -732,11 +738,11 @@ class _SuppressCoreFiles(object):
 | 
			
		|||
 | 
			
		||||
    def __enter__(self):
 | 
			
		||||
        """Try to save previous ulimit, then set it to (0, 0)."""
 | 
			
		||||
        if resource is not None:
 | 
			
		||||
            try:
 | 
			
		||||
            import resource
 | 
			
		||||
                self.old_limit = resource.getrlimit(resource.RLIMIT_CORE)
 | 
			
		||||
                resource.setrlimit(resource.RLIMIT_CORE, (0, 0))
 | 
			
		||||
        except (ImportError, ValueError, resource.error):
 | 
			
		||||
            except (ValueError, resource.error):
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
        if sys.platform == 'darwin':
 | 
			
		||||
| 
						 | 
				
			
			@ -758,10 +764,10 @@ def __exit__(self, *args):
 | 
			
		|||
        """Return core file behavior to default."""
 | 
			
		||||
        if self.old_limit is None:
 | 
			
		||||
            return
 | 
			
		||||
        if resource is not None:
 | 
			
		||||
            try:
 | 
			
		||||
            import resource
 | 
			
		||||
                resource.setrlimit(resource.RLIMIT_CORE, self.old_limit)
 | 
			
		||||
        except (ImportError, ValueError, resource.error):
 | 
			
		||||
            except (ValueError, resource.error):
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue