# Slicer often crashes when running with python-script in loading

**URL:** <https://discourse.slicer.org/t/slicer-often-crashes-when-running-with-python-script-in-loading/23719>\
**Category:** Support\
**Created:** [June 6, 2022, 1:07am UTC](https://discourse.slicer.org/t/slicer-often-crashes-when-running-with-python-script-in-loading/23719 "2022-06-06T01:07:31Z")\
**Posts on this page:** 1\
**Showing post:** 11

<div class="post-metadata">

**Author:** ![pieper](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/pieper/32/8_2.png) [@pieper](https://discourse.slicer.org/u/pieper)\
**Post date:** [February 17, 2023, 5:52pm UTC](https://discourse.slicer.org/t/slicer-often-crashes-when-running-with-python-script-in-loading/23719/11 "2023-02-17T17:52:21Z")

</div>

The ideal would be to put the data someplace like a public google drive folder or pull them from IDC and then provide a python script that downloads the data and then runs the simplest script that replicates the crash you are seeing. This way it would be possible to see if the issue is with the data, the script, the docker configuration or something else.

For example, here’s the task I did yesterday to make nifti files and screen grabs for all the files in the [CBM-CRC collection](https://doi.org/10.7937/djg7-gz87) on IDC. This pulls down more data than we’d want for trying to replicate the crash, but it should give you an idea how to make a reproducible example.

First I got the list of URLs:

```auto
bq query -n 50000 --format=csv --use_legacy_sql=false \
  'SELECT gcs_url FROM `bigquery-public-data.idc_current.dicom_all` WHERE collection_id = "cmb_crc" LIMIT 50000' \
    > cbm_crc-urls.csv

```

Then I downloaded them all to a local directory:

```auto
mkdir cbm_crc
cat cbm_crc-urls.csv| tail -n +2 | gsutil -m cp -I cbm_crc

```

In Slicer, I imported that directory into a new dicom database and then ran this script:

```auto
from DICOMLib import DICOMUtils

niiDir = "/opt/data/idc/cbm_crc-nii"

db = slicer.dicomDatabase
for patient in db.patients():
    for study in db.studiesForPatient(patient):
        accessionNumber = db.fieldForStudy("AccessionNumber", study)
        if accessionNumber == "":
            accessionNumber = study
        for series in db.seriesForStudy(study):
            slicer.mrmlScene.Clear()
            loadedNodeIDs = DICOMUtils.loadSeriesByUID([series])
            if len(loadedNodeIDs) != 1:
                print(f"Skipping {series} because it generated {len(loadedNodeIDs)} nodes")
                continue
            seriesDescription = db.fieldForSeries("SeriesDescription", series)
            seriesDescription = seriesDescription.replace(" ", "_").replace("/","-")
            seriesNumber = int(db.fieldForSeries("SeriesNumber", series))
            niiPath = f"{niiDir}/{accessionNumber}_{seriesNumber}_{seriesDescription}.nii.gz"
            pngPath = f"{niiDir}/{accessionNumber}_{seriesNumber}_{seriesDescription}.png"
            slicer.util.delayDisplay(niiPath, 100)
            print(niiPath)
            slicer.util.saveNode(slicer.util.getNode(loadedNodeIDs[0]), niiPath)
            slicer.util.mainWindow().centralWidget().grab().toImage().save(pngPath)

```

The whole process took a few hours but no crashes.

---

_[View the full topic](https://discourse.slicer.org/t/slicer-often-crashes-when-running-with-python-script-in-loading/23719)._
