b958f5b446
* working base with merged ui repo * include project search * widgets * working cards * remove .pyc files * again * add gitignore * nice hovers * interactive background working * beautiful search * working widgets * optimized * project query * all working * models show up but only from the last stream * fixed models * cleaner * model search moved * add models * UI models and bindings * rearrangement * moved folder * cleanup * rearrange * rename1 * rename2 * cleanup * rename1 * rename2 * hide old ui * bindings added * rename * still works * works * works except resize * project scroll working * scroll down * load button fixed * emit sender card to dockwidget * models cards added * model cards recognized * resize * publish works * cards created in the right order * fix order * styling * perfect model card * visuals * remove widget btn * publish button to the bottom * add and remove model cards faster * remove old code * stretch cards
63 lines
1.8 KiB
Python
63 lines
1.8 KiB
Python
|
|
import sys
|
|
import trace
|
|
import threading
|
|
|
|
class KThread(threading.Thread):
|
|
"""A subclass of threading.Thread, with a kill()
|
|
method."""
|
|
# https://web.archive.org/web/20130503082442/http://mail.python.org/pipermail/python-list/2004-May/281943.html
|
|
def __init__(self, *args, **keywords):
|
|
threading.Thread.__init__(self, *args, **keywords)
|
|
self.killed = False
|
|
|
|
def start(self):
|
|
"""Start the thread."""
|
|
self.__run_backup = self.run
|
|
self.run = self.__run # Force the Thread to install our trace.
|
|
threading.Thread.start(self)
|
|
|
|
def __run(self):
|
|
"""Hacked run function, which installs the trace."""
|
|
sys.settrace(self.globaltrace)
|
|
self.__run_backup()
|
|
self.run = self.__run_backup
|
|
|
|
def globaltrace(self, frame, why, arg):
|
|
if why == 'call':
|
|
return self.localtrace
|
|
else:
|
|
return None
|
|
|
|
def localtrace(self, frame, why, arg):
|
|
if self.killed:
|
|
if why == 'line':
|
|
raise SystemExit()
|
|
return self.localtrace
|
|
|
|
def kill(self):
|
|
self.killed = True
|
|
|
|
class KillableThread(threading.Thread):
|
|
# is NOT running in the background
|
|
# https://stackoverflow.com/questions/323972/is-there-any-way-to-kill-a-thread
|
|
def __init__(self, sleep_interval=1):
|
|
super().__init__()
|
|
self._kill = threading.Event()
|
|
self._interval = sleep_interval
|
|
|
|
def run(self):
|
|
while True:
|
|
print("Do Something")
|
|
|
|
# If no kill signal is set, sleep for the interval,
|
|
# If kill signal comes in while sleeping, immediately
|
|
# wake up and handle
|
|
is_killed = self._kill.wait(self._interval)
|
|
if is_killed:
|
|
break
|
|
|
|
print("Killing Thread")
|
|
|
|
def kill(self):
|
|
self._kill.set() |