Skip to content

Instantly share code, notes, and snippets.

@davidfraser
Last active May 18, 2017 14:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidfraser/a560be999adc235231eb8c60d7e5a0f5 to your computer and use it in GitHub Desktop.
Save davidfraser/a560be999adc235231eb8c60d7e5a0f5 to your computer and use it in GitHub Desktop.
Demonstration of hang when coloredlogs in one thread and import in other thread does logging
#!/usr/bin/env python
import logging
import time
import threading
import coloredlogs
# configured notices that will be displayed with styling by coloredlogs
NOTICE = 25
logging.addLevelName(25, 'notice')
def background_thread():
time.sleep(1)
logging.log(NOTICE, "background thread is progressing")
logging.info("Time to say goodbye")
return
def main_thread():
coloredlogs.install(level='INFO')
background = threading.Thread(target=background_thread)
try:
background.start()
logging.info("Main thread doing import")
import hang_helper1
logging.info("Main thread completed import")
finally:
background.join()
if __name__ == '__main__':
main_thread()
#!/usr/bin/env python
import time
import logging
# simulate a slow and more complicated import, that also does some logging
for n in range(10):
logging.info("Time is ticking away")
time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment