I am attempting to convert a Python script to Golang, just really to see performance differences and to help me learn Golang more.
In Python, I have 2 scripts. One is a script that runs an infinite loop and sleeps for a minute before running again. The code checks an endpoint on my server and reads the output, then determines if it needs to do anything. If it does, it handles the output and starts a new subprocess. The subprocess is another Python script that does a lot of calculations and creates hundreds of threads. There can be multiple subprocesses running at any given time and they're all different tasks for different users.
I've got my Golang code reading from the API, and it's ready to start a new subprocess. But I'm not really sure how I go about it.
I know when I've created the new subprocess (or whatever it is that is the Go equivalent) I can create a bunch of Go routines, but really I'm just stuck on the "subprocess" bit.
I have tried using Go routines as a substitute for the subprocess but I don't think this is the way to go?
As requested for visualisation purposes, I have added an example of the code.
api.py:
while True:
someparameter = 'randomIDfromdatabase'
subprocess.Popen(["python3", "mycode.py", someparameter])
time.sleep(60)
mycode.py
parameter = sys.argv[1]
for i in range(0, 100):
thread.append(MyClass(parameter))
thread.start()
I basically need the Golang equivalent of "subprocess.Popen".