code: def managing_thread_main_simple():
  	
  	import shutit_global
  	last_msg = ''
  	while True:
  		printed_anything = False
  		if shutit_global.shutit_global_object.log_trace_when_idle and time.time() - shutit_global.shutit_global_object.last_log_time > 10:
  			this_msg = ''
  			this_header = ''
  			for thread_id, stack in sys._current_frames().items():
  				# ignore own thread:
  				if thread_id == threading.current_thread().ident:
  					continue
  				printed_thread_started = False
  				for filename, lineno, name, line in traceback.extract_stack(stack):
  					if not printed_anything:
  						printed_anything = True
  						this_header += '\n='*80 + '\n'
  						this_header += 'STACK TRACES PRINTED ON IDLE: THREAD_ID: ' + str(thread_id) + ' at ' + time.strftime('%c') + '\n'
  						this_header += '='*80 + '\n'
  					if not printed_thread_started:
  						printed_thread_started = True
  					this_msg += '%s:%d:%s' % (filename, lineno, name) + '\n'
  					if line:
  						this_msg += '  %s' % (line,) + '\n'
  			if printed_anything:
  				this_msg += '='*80 + '\n'
  				this_msg += 'STACK TRACES DONE\n'
  				this_msg += '='*80 + '\n'
  			if this_msg != last_msg:
  				print(this_header + this_msg)
  				last_msg = this_msg
  		time.sleep(5)
docs: Simpler thread to track whether main thread has been quiet for long enough
  	that a thread dump should be printed.