this is my class:
class Task:
__slots__ = ('callback', 'args')
def __init__(self, callback: 'Callable', *args):
self.callback = callback
self.args = args
def execute(self):
try:
self.callback(*self.args)
except BaseException:
print(traceback.print_exc())
I have a thread that consumes a queue of these tasks:
def check_queue_tasks(self):
while self.running:
Tasks.queue.get()
Tasks.get_task().execute()
Tasks.remove_task()
Tasks.queue.task_done()
I have several scripts that create tasks and push them to the queue, so in the life of this program thousands of tasks could be created that of course will die when they are executed.
The key question is, should I use slots for this class? does this save memory? improves the speed in the execution of tasks in the queue? or does it just make it worse for this case?