0

I am writing a program which uses a loop to run several Prism (a graphing program) scripts, exporting PNGs. However, I am having some difficulty with how Prism runs, and I have a couple of suspicions about what might be causing the problem, listed here:

  1. Prism is not finished doing everything it needs to do before I call it again
  2. I am using the wrong sort of pipeline to the command line, although I have also tried subprocess.popen() and os.system()
  3. For whatever reason the command I send to command line is waiting on the program for something

Some strange behaviour that I have encountered is that when I run the program, the Prism startup 'label' shows up on the screen but doesn't go away after a few seconds, indicating to me that Prism has started but is being prevented from running by my code (the particular code I think is causing this is shown below). Additionally, the window I create becomes unresponsive so I have to close the program. However, after I close it, Prism runs the script and I get the exported PNGs from one of the scripts (also indicating that the program might be preventing Prism from running).

A little bit of the code in question is:

    os.popen(create_full_prism_path(create_script_name(f)).replace('/', '\\'))
    while (not(path.exists(root.output_path + "\\" + f + ".TV.png"))):
        pass

Where create_full_prism_path(create_script_name(f)).replace('/', '\\') is the command being sent to the command line - I have tested printing and running this command after everything has run, and it works just fine.

while (not(path.exists(root.output_path + "\\" + f + ".TV.png"))):
        pass

is the while loop I am using to check that before I go through the loop again, Prism has actually created the PNG I am asking for.

I have tried workarounds to this problem but I can't seem to find a solution, does anyone know how this problem can be solved?

  • Have you tried `subprocess.run()`? This will block until the command you pass is finished. – Michael Mitter Jun 18 '20 at 21:12
  • I just tried that, what seems to still happen is that Prism doesn't actually run the script I tell it to until I close the program. Additionally, the window stops responding. – Willsherl Jun 18 '20 at 21:41
  • I see, have you tried setting the `shell=True` parameter of `subprocess.run()`? Some commands don't work properly without that ( see this [answer](https://stackoverflow.com/questions/3172470/actual-meaning-of-shell-true-in-subprocess)) – Michael Mitter Jun 18 '20 at 21:51
  • I have tried it with shell=true, same thing happens basically. Still runs properly after I forcibly close the program – Willsherl Jun 18 '20 at 22:22

0 Answers0