sys.stderr.echo

Here are the examples of the python api sys.stderr.echo taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

1 Examples 7

Example 1

Project: solutions-geoprocessing-toolbox Source File: ALFlib.py
	def _applyHooks(self):
		# Apply Hooks to Exception and Exit handlers
		def exceptionHook( type, value, tb):
			print "\n* Un-handled Exception Detected *"
			echoWas = sys.stderr.echo
			sys.stderr.echo = True
			
			for line in traceback.format_exception( type, value, tb):
				sys.stderr.write( line)
			sys.stderr.write( '\n')
			
			if not self._exitValue:	# Report error in Archive on first encounter
				self.archive( "* Un-handled Exception Detected, details: '{0}' *".format( self._errorLog))
			
			sys.stderr.echo = echoWas
			self._exitValue = 'Exception'
		
		def exitHook( value=0):
			# Fired before 'atexit' Hook when 'sys.exit' invoked, save Exit value
			self._exitValue = value
			_origExit( value)
		
		def atexitHook():
			# Load Exit value, 'exitHook' not fired if clean exit and 'sys.exit' not invoked
			value = self._exitValue
			
			if self._singleton:
				# Release Application Lock on early exit file
				self._singleton.unlock()
			
			sys.stderr.write( "\nFinished: {0}\n".format( datetime.datetime.now().strftime( '%H:%M:%S %a %m/%d/%Y')))
			
			if value:
				if value == 'Exception':
					return
				
				if isinstance( value, str) or isinstance( value, unicode):
					sys.stderr.write( "\n* Error Exit detected: {0}\n".format( value))
				else:
					print "\n* Error Exit '{0}' detected *".format( value)
				
				self.archive( "* Error Exit detected, details: '{0}' *".format( self._errorLog))
			else:
				# Clean exit, no need to keep Error Log so remove it, unless keep
				# activity has been set to True!
				self._errorFP.close()
				self._errorFP = False

				if not self._keepActivity:
					# Remove it!
					os.remove( self._errorLog)
				else:
					# Rename it!
					path, filename = os.path.split( self._errorLog)
					name, ext = filename.split('.')
					activityFile = os.path.join( path, name + '_activity.' + ext)
					os.rename( self._errorLog, activityFile)
		
		self._exitValue = False			# Set initial Exit value
		_origExit = sys.exit			# Save current Exit handle
		sys.exit = exitHook			# Override Exit handle
		atexit.register( atexitHook)		# Register Exit Hook
		sys.excepthook = exceptionHook	# Override Exception handle