I have a simple code that runs a function in the process. This function append numbers to the list. In my version of the code, I get an empty list. How to get this list after clicking on the stop button?
from multiprocessing import Process
from flask import Flask
app = Flask(__name__)
logs = []
def test():
for i in range(100):
logs.append(i)
time.sleep(1)
@app.route('/', methods=['POST', 'GET'])
def main():
global p
if request.method == 'POST':
index = request.form['index']
if index == 'start':
p = Process(target = test)
p.start()
if index == 'stop':
print(logs)
p.kill()
return redirect(url_for('main'))
return render_template('index.html')
app.run(debug=True)