Last active
May 18, 2017 14:27
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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() | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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