Jan-15-2018, 03:22 PM
I'm having an issue with text output from a thread staying visible in the interpreter. The code below can be used to demonstrate the problem following these steps.
1. Place the code into a file.
2. Start Python 2.7 and import the file.
3. Execute the startThread() function to start the thread.
At this point you should see "hello world" printed every 3 seconds. The issue is that when any key is pressed the all the "hello world" text disappears. I need to find a way to maintain the text printed by the thread in the interpreter. Any ideas or help is appreciated.
1. Place the code into a file.
2. Start Python 2.7 and import the file.
3. Execute the startThread() function to start the thread.
At this point you should see "hello world" printed every 3 seconds. The issue is that when any key is pressed the all the "hello world" text disappears. I need to find a way to maintain the text printed by the thread in the interpreter. Any ideas or help is appreciated.
from __future__ import print_function
import threading
import time
class TestThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self, name='test')
self._done = False
def run(self):
while not self._done:
print("hello world")
time.sleep( 3 )
def close(self):
self._done = True
td = None
def startThread( ):
global td
print( "Starting thread.")
td = TestThread( )
td.setDaemon( True )
td.start( )
