If you want to automatically rerun a process when a file changes, use watchfiles.
In the code above, the function train will run when the file process_data.py changes.
train
process_data.py
Link to watchfiles.