Commit 52fafc67 authored by Christian Wander's avatar Christian Wander
Browse files

starting and stopping threads

parent d8892c4f
......@@ -16,3 +16,8 @@ def hello_method():
def threadfun():
t.doit()
return "Started work."
@app.route('/threadstop')
def threadstop():
t.stopit()
return "Stopped work"
\ No newline at end of file
import threading
import threading, queue
import time
running = False
def doit():
global running
if running is True:
print(">> DEBUG: already running.")
return
print(f'>> Starting a thread ...')
x = threading.Thread(target=threaded_function)
running = True
x = threading.Thread(target=threaded_function, daemon=True)
x.start()
print(f'>> Thread started.')
def stopit():
global running
running = False
def threaded_function():
print(f'>> Doing some work within thread ...')
time.sleep(2)
while running is True:
print(f'>> Doing some work within thread, running={running} ')
time.sleep(2)
print(f'>> Finished work within thread!')
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment