On_click function assigned to button runs without clicking

I’ve assigned an on_funtion to a button .Which is supposed to run a python file and start capturing the webcam. It should only be started when the button is clicked . But whenever i run the streamlit server the function runs and start capturing without a click event

import subprocess
import sys
import streamlit as st
from activity_check import high_count
act_lev = ""
def start_capture(act_lev):
	subprocess.run([f"{sys.executable}", "activity_check.py"])
def run_cap():
	st.button("Start Capturing",on_click=start_capture)
run_cap()
st.write(high_count)

Any idea why this is happening?

No, the function does not run. What is happening is probably that importing activity_check starts the capture.

In this simplified example, I can confirm that the on_click does not run until the first click happens, so I suspect that @Goyo is on the righ trail, that start_capture (or the subprocess call) is being triggered some other way.

import streamlit as st


def start_capture():
    st.write("# CLICKED")

def run_cap():
	st.button("Start Capturing",on_click=start_capture)

run_cap()