Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Chris
Pixelframe
Commits
52fafc67
Commit
52fafc67
authored
Dec 22, 2020
by
Christian Wander
Browse files
starting and stopping threads
parent
d8892c4f
Changes
2
Hide whitespace changes
Inline
Side-by-side
pixelframe/controllers.py
View file @
52fafc67
...
...
@@ -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
pixelframe/threadfun.py
View file @
52fafc67
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!'
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment