# Run python script in thread cause crash

**URL:** <https://discourse.slicer.org/t/run-python-script-in-thread-cause-crash/40139>\
**Category:** Development\
**Tags:** python\
**Created:** [November 12, 2024, 1:42am UTC](https://discourse.slicer.org/t/run-python-script-in-thread-cause-crash/40139 "2024-11-12T01:42:22Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![fqzhice](https://avatars.discourse-cdn.com/v4/letter/f/7bcc69/32.png) [@fqzhice](https://discourse.slicer.org/u/fqzhice)\
**Post date:** [November 12, 2024, 1:42am UTC](https://discourse.slicer.org/t/run-python-script-in-thread-cause-crash/40139/1 "2024-11-12T01:42:22Z")

</div>

Hi  
I try to run heavy calculation by qtimer  
cmd = “pythonSlicerExecutablePath=os.path.dirname(sys.executable)+‘/PythonSlicer.exe’\n”  
“commandLine = [pythonSlicerExecutablePath, script, ‘%1’]\n”  
“proc=slicer.util.launchConsoleProcess( commandLine ,useStartupEnvironment=True)\n”

…  
PythonQt::init();  
PythonQtObjectPtr context = PythonQt::self()-\>getMainModule();  
QTimer timer;  
timer.singleShot(0,this, & {  
context.evalScript(cmd);  
});  
the set a progressbar for main thread.  
but it cashed with PythonQt accession error

Any suggestion vill very appreciated
