Welcome, @ellie.95!
In Anvil, the center of control generally resides in the Client, i.e., the instance of the App that runs in the browser. This is because Python code running in this instance can call other Python code, running elsewhere, but not vice versa.
For examples, see Uplink: Code outside Anvil.
In particular, this shows how a Python program running on your PC can be polled by your Client code, running in any browser, anywhere.
There are more specific examples here, in Q&A, of other people doing exactly this sort of thing. A closer look at how they did it, should offer some more concrete clues than I can.