mirror of
https://git.mirrors.martin98.com/https://github.com/Ultimaker/Cura
synced 2025-06-04 11:14:21 +08:00
Fix call_on_qt_thread decorator
CURA-6225 Do thread check in the wrapper function, not outside.
This commit is contained in:
parent
ace638ec81
commit
f521fae152
@ -1,3 +1,4 @@
|
|||||||
|
import functools
|
||||||
import threading
|
import threading
|
||||||
|
|
||||||
from cura.CuraApplication import CuraApplication
|
from cura.CuraApplication import CuraApplication
|
||||||
@ -6,7 +7,7 @@ from cura.CuraApplication import CuraApplication
|
|||||||
#
|
#
|
||||||
# HACK:
|
# HACK:
|
||||||
#
|
#
|
||||||
# In project loading, when override the existing machine is selected, the stacks and containers that are correctly
|
# In project loading, when override the existing machine is selected, the stacks and containers that are currently
|
||||||
# active in the system will be overridden at runtime. Because the project loading is done in a different thread than
|
# active in the system will be overridden at runtime. Because the project loading is done in a different thread than
|
||||||
# the Qt thread, something else can kick in the middle of the process. One of them is the rendering. It will access
|
# the Qt thread, something else can kick in the middle of the process. One of them is the rendering. It will access
|
||||||
# the current stacks and container, which have not completely been updated yet, so Cura will crash in this case.
|
# the current stacks and container, which have not completely been updated yet, so Cura will crash in this case.
|
||||||
@ -22,7 +23,13 @@ class InterCallObject:
|
|||||||
|
|
||||||
|
|
||||||
def call_on_qt_thread(func):
|
def call_on_qt_thread(func):
|
||||||
|
@functools.wraps(func)
|
||||||
def _call_on_qt_thread_wrapper(*args, **kwargs):
|
def _call_on_qt_thread_wrapper(*args, **kwargs):
|
||||||
|
# If the current thread is the main thread, which is the Qt thread, directly call the function.
|
||||||
|
current_thread = threading.current_thread()
|
||||||
|
if isinstance(current_thread, threading._MainThread):
|
||||||
|
return func(*args, **kwargs)
|
||||||
|
|
||||||
def _handle_call(ico, *args, **kwargs):
|
def _handle_call(ico, *args, **kwargs):
|
||||||
ico.result = func(*args, **kwargs)
|
ico.result = func(*args, **kwargs)
|
||||||
ico.finish_event.set()
|
ico.finish_event.set()
|
||||||
|
@ -44,8 +44,12 @@ class UFPWriter(MeshWriter):
|
|||||||
# trigger loading other containers. Because those loaded containers are QtObjects, they must be created on the
|
# trigger loading other containers. Because those loaded containers are QtObjects, they must be created on the
|
||||||
# Qt thread. The File read/write operations right now are executed on separated threads because they are scheduled
|
# Qt thread. The File read/write operations right now are executed on separated threads because they are scheduled
|
||||||
# by the Job class.
|
# by the Job class.
|
||||||
@call_on_qt_thread
|
|
||||||
def write(self, stream, nodes, mode = MeshWriter.OutputMode.BinaryMode):
|
def write(self, stream, nodes, mode = MeshWriter.OutputMode.BinaryMode):
|
||||||
|
print("------------> self _write = ", self._write)
|
||||||
|
return self._write(stream, nodes, mode = mode)
|
||||||
|
|
||||||
|
@call_on_qt_thread
|
||||||
|
def _write(self, stream, nodes, mode = MeshWriter.OutputMode.BinaryMode):
|
||||||
archive = VirtualFile()
|
archive = VirtualFile()
|
||||||
archive.openStream(stream, "application/x-ufp", OpenMode.WriteOnly)
|
archive.openStream(stream, "application/x-ufp", OpenMode.WriteOnly)
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user