Error while calling through subprocess.run() in Python

Viewed 31

I am trying to runNormal.py by using subprocess.run(). However, it finishes running and displays return code 1. I present Normal.py and the error below fully. Please help if you can.

import subprocess

print(subprocess.run(['python',rf'C:\\Users\\USER\\OneDrive - Technion\\Research_Technion\\Python_PNM\\Sept15_2022\\Test2\\1\\Normal.py'])) 

Normal.py is

import os

Runs=2

def function(run):
    from scipy.stats import truncnorm
    import numpy as np
    import csv 
    # Create the folder with the number of the run as name
    # Add 1 to run so the first run is 1 and not 0
    parent_folder = str(run + 1)
    os.mkdir(parent_folder)

    a, b = 47.0,53.0
    Nodes=220  #reshape into
    r = (1e-6)*np.linspace(truncnorm.ppf(0.001, a, b),truncnorm.ppf(1.0, a, b), Nodes)
    print("r =",[r])

    sort_r = np.sort(r); 
    r1=sort_r[::-1]
    print("r1 =",[r1])
    #print("r =",[r])

    r1=r1.reshape(1,Nodes)
    print("r1 shape =",[r1])

    r2 = r.copy()

    # r2.ravel() returns a view of the original array
    # so we can shuffle only the items starting from 1
    np.random.shuffle(r2.ravel()[1:])
    print("r2 =",[r2])    

    r2=r2.reshape(1,Nodes)
    print("r2 =",[r2])                          #actual radius values in mu(m)

    maximum = r2.max()
    indice1 = np.where(r2 == maximum)
    # minimmum = r2.min()
    # indice2 = np.where(r2 == minimum)
    r2[indice1] = r2[0][0]
    r2[0][0] = maximum
    #print(r2)
    r2[0][Nodes-1] = maximum  #+0.01*maximum
    #print(r2)
    print("r2 with max at (0,0)=",[r2])

    ######################################

    # make a copy and shuffle the copy
    # r2 = r.copy()
    # np.random.shuffle(r2.ravel())

    # # get the index of the max
    # idx = np.unravel_index(r2.argmax(), r2.shape)

    # # swap first and max
    # r2[idx], r2[(0, 0)] = r2[(0, 0)], r2[idx]

    # print(r2)


    ######################################

    with open(os.path.join(parent_folder, 'Inv_Radius_220_47_53ND.csv'), 'w+') as f: 
        inv_r=1/r2
        print("inv_r =",[inv_r])
        writer = csv.writer(f)
        writer.writerows(inv_r)
     

    mean=np.mean(r)
    print("Mean =",mean)
    var=np.var(r)
    print("var =",var)
    std=np.std(r)
    print("std =",std)

    with open(os.path.join(parent_folder,'Radius info _220_47_53ND.txt'), 'w+') as f: 
        
            f.write(f"mean = {str(mean)}\n")
            f.write(f"var = {str(var)}\n")
            f.write(f"std = {str(std)}\n")


for x in range(Runs):
    function(x)

The error is

CompletedProcess(args=['python', 'C:\\\\Users\\\\USER\\\\OneDrive - Technion\\\\Research_Technion\\\\Python_PNM\\\\Sept15_2022\\\\Test2\\\\1\\\\Normal.py'], returncode=1)
0 Answers
Related