Improving reliability of threaded rendering, separating JS Utils into separate files.
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
49e94317d4
commit
687b14429a
18 changed files with 285 additions and 197 deletions
|
@ -21,9 +21,10 @@ from platform import system as os_name, release as OS_RELEASE
|
|||
from sys import path as sys_path
|
||||
from sys import argv, exit
|
||||
from tempfile import TemporaryDirectory
|
||||
from math import ceil
|
||||
from time import time
|
||||
|
||||
from PySide6.QtCore import QTranslator, QLocale
|
||||
from PySide6.QtCore import QTranslator, QLocale, QThreadPool, QThread
|
||||
from PySide6.QtGui import QIcon
|
||||
from PySide6.QtQml import QQmlApplicationEngine
|
||||
from PySide6.QtQuickControls2 import QQuickStyle
|
||||
|
@ -162,7 +163,11 @@ def run():
|
|||
|
||||
dep_time = time()
|
||||
print("Loaded dependencies in " + str((dep_time - start_time) * 1000) + "ms.")
|
||||
|
||||
|
||||
# Maxing thread count to half the computer's thread count to avoid maxing CPU
|
||||
# with too many threads (and also leaving some for rendering).
|
||||
QThreadPool.globalInstance().setMaxThreadCount(int(ceil(QThread.idealThreadCount() / 2)))
|
||||
|
||||
register_icon_directories()
|
||||
app = create_qapp()
|
||||
translator = install_translation(app)
|
||||
|
|
|
@ -22,6 +22,8 @@ from PySide6.QtQml import QJSValue
|
|||
|
||||
from LogarithmPlotter.util.js import PyJSValue
|
||||
|
||||
NO_RETURN = [None, QJSValue.SpecialValue.UndefinedValue]
|
||||
|
||||
|
||||
def check_callable(function: Callable|QJSValue) -> Callable|None:
|
||||
"""
|
||||
|
@ -153,13 +155,12 @@ class PyPromise(QObject):
|
|||
@Slot(QObject)
|
||||
def _fulfill(self, data):
|
||||
self._state = "fulfilled"
|
||||
no_return = [None, QJSValue.SpecialValue.UndefinedValue]
|
||||
print("Finished", self._runner.args)
|
||||
for i in range(len(self._fulfills)):
|
||||
try:
|
||||
result = self._fulfills[i](data)
|
||||
result = result.qjs_value if isinstance(result, PyJSValue) else result
|
||||
data = result if result not in no_return else data # Forward data.
|
||||
data = result if result not in NO_RETURN else data # Forward data.
|
||||
except Exception as e:
|
||||
self._reject(repr(e), start_at=i)
|
||||
break
|
||||
|
@ -168,8 +169,7 @@ class PyPromise(QObject):
|
|||
@Slot(str)
|
||||
def _reject(self, error, start_at=0):
|
||||
self._state = "rejected"
|
||||
no_return = [None, QJSValue.SpecialValue.UndefinedValue]
|
||||
for i in range(start_at, len(self._rejects)):
|
||||
result = self._rejects[i](error)
|
||||
result = result.qjs_value if isinstance(result, PyJSValue) else result
|
||||
error = result if result not in no_return else error # Forward data.
|
||||
error = result if result not in NO_RETURN else error # Forward data.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue