swingmusic/app/utils/threading.py
mungai-njoroge 258897b649 add silence removal using pydub and multithreading
+ fix favorites endpoint returning items less than limit
+ add endpoint to remove get silence padding
+ add 'the ulitimate' and 'compilation' to compilation album filters
+ misc
2024-01-05 01:08:07 +03:00

35 lines
842 B
Python

import threading
def background(func):
"""
Runs the decorated function in a background thread.
"""
def background_func(*a, **kw):
threading.Thread(target=func, args=a, kwargs=kw).start()
return background_func
class ThreadWithReturnValue(threading.Thread):
"""
A thread class that returns a value on join.
Credit: https://stackoverflow.com/a/6894023
"""
def __init__(
self, group=None, target=None, name=None, args=(), kwargs={}, Verbose=None
):
threading.Thread.__init__(self, group, target, name, args, kwargs)
self._return = None
def run(self):
if self._target is not None:
self._return = self._target(*self._args, **self._kwargs)
def join(self, *args):
threading.Thread.join(self, *args)
return self._return