Is there a way to open a second python console and let the new console run while the original console keeps going and when the new console finishes it sends back its data, in the form of a variable back to the original console?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The
sub-processmodule might be what you are looking for. However, the thing is, you get the output of the process after the entire program finishes. this means, if the program you are trying to run runs forever you will not be able to see the output until it is quit (either by forcing it or using termination methods).An example of how you would assign the output to a variable would be:
The output part of this is what you would be using (based on your question). However, the error is what you get if you run it and there is a problem (doesn’t return 0). If you are not looking to capture errors then you can simply assign it to
_.Also note that if you are using key-word arguments, i would suggest using the
shlexlibrary for splitting your string into arguments. (you can just use a regular string such as:var="mypythonprogram.py argument1 argument2"and usearguments=shlex.split(var)and you can then just supply it into the arguments for the sub-process.Another option if you don’t need to interact with the program would be using Threads, and there are many questions on stack overflow about them, as well as plenty of documentation both officially, and on other websites all over the internet.