mirror of
https://github.com/spalencsar/bearhub.git
synced 2026-07-08 15:34:15 +02:00
project renamed as 'bauh'
This commit is contained in:
31
bauh/core/worker.py
Normal file
31
bauh/core/worker.py
Normal file
@@ -0,0 +1,31 @@
|
||||
from io import StringIO
|
||||
from threading import Thread
|
||||
|
||||
from colorama import Fore
|
||||
|
||||
from bauh.core.model import Application
|
||||
|
||||
|
||||
class AsyncDataLoader(Thread):
|
||||
|
||||
def __init__(self, app: Application):
|
||||
super(AsyncDataLoader, self).__init__(daemon=True)
|
||||
self.id_ = '{}#{}'.format(self.__class__.__name__, id(self))
|
||||
self.app = app
|
||||
|
||||
def log_msg(self, msg: str, color: int = None):
|
||||
final_msg = StringIO()
|
||||
|
||||
if color:
|
||||
final_msg.write(str(color))
|
||||
|
||||
final_msg.write('[{}] '.format(self.id_))
|
||||
|
||||
final_msg.write(msg)
|
||||
|
||||
if color:
|
||||
final_msg.write(Fore.RESET)
|
||||
|
||||
final_msg.seek(0)
|
||||
|
||||
print(final_msg.read())
|
||||
Reference in New Issue
Block a user