Python Forum
Running two consecutive scripts in VSCode
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Running two consecutive scripts in VSCode
#1
I'm trying to find a way to run two consecutive scripts in two different terminal sessions in VSCode.
There's no problem running two sessions, only problem is that output is shown in same terminal session, making it very difficult (almost impossible, actually) to distinguish between session outputs.

I've been looking, but so far haven't found a way to direct output to a particular terminal session.
Anybody figure this one out?

Added Edit:
I found one way, which is not too painful.
  • Open a new terminal session with Ctrl-Shift`
  • Run run code by issuing 'python script.py' from terminal prompt.

Still, a simple redirect would be nice.
Reply
#2
Mods, please send this to a VSCode forum
Reply
#3
(Mar-10-2019, 07:23 PM)woooee Wrote: Mods, please send this to a VSCode forum
Huh? The OP is a mod, and as another mod, I don't know what you're talking about - we don't have a VSCode subforum, nor do we transfer posts to other websites.
Reply
#4
The problem is controlling output in 2 VSCode sessions. The Python code is running fine. It is possible that there is a Python solution to the problem, i.e. multiprocessing/threading would solve the problem, but we have no code to work with.

A simple program that sends data to a Tkinter Listbox instead of the shell. Don't know if this will help or not, and you may have to use multiprocessing/threading for each separate program instance, but the listbox code would remain similar to this
## program name = test_1.py
def update_listbox(listbox, ctr, time_to_sleep):
    listbox.insert("end", "%s" % (ctr))
    listbox.after(time_to_sleep, update_listbox, listbox, ctr+1, time_to_sleep)

## different program
import tkinter as tk
import multiprocessing
import test_1

class CalculateNumbers():
    def __init__(self, root):
        self.root=root
        tk.Button(self.root, text="Quit", bg="orange",
               command=self.root.quit, width=7).grid()

        self.lb_1 = self.create_listbox("lightblue")
        test_1.update_listbox(self.lb_1, 1, 500)
        self.lb_2 = self.create_listbox("lightyellow")
        test_1.update_listbox(self.lb_2, 11, 750)

    def create_listbox(self, bg_color):
        top=tk.Toplevel(root)
        lb = tk.Listbox(top, height=30, width=20, bg=bg_color,
                        font=('Fixed', 14))
        lb.grid(row=0, column=0)

        return lb

if __name__ == "__main__":
    root=tk.Tk()
    CN=CalculateNumbers(root)
    root.mainloop()
Reply
#5
I don't use VSCode, so have nothing to contribute, but we do often help with Python-adjacent things here. Tooling is fine; we used to have a forum for it, but it didn't get enough traffic so got dropped at one point, but it wasn't because we didn't want the questions here.
Reply
#6
I cant think why would VScode would dump the stdout to once terminal session when they started on two different terminal session? In any case, im not sure using multi-processing would actually solve this particular issue.
Reply
#7
I assure you, if you have two scripts loaded, and you try to run both at the same time, they will be directed to the same terminal session.
Woooee. This is a python forum. VSCode is an IDE that is used by many Python users. Should I ban myself?
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  running py3 scripts as root Skaperen 4 2,073 Dec-18-2019, 12:31 AM
Last Post: Skaperen

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020