Home > OS >  Python, updating variables manual while code running
Python, updating variables manual while code running

Time:05-15

I have a code that contains a variable that I want to change manually when I want without stopping the main loop neither pause it (with input()). I can't find a library that allows me to set manually in the run, or access the RAM memory to change that value. for now I set a file watcher that reads the parameters every 1 minutes but this is inefficient way I presume.

CodePudding user response:

I guess you just want to expose API. You did it with files which works but less common. You can use common best practices such as:

  1. HTTP web-server. You can do it quickly with Flask/bottle.
  2. gRPC
  3. pub/sub mechanism - Redis, Kafka (more complicated, requires another storage solution - the DB itself).

I guess that there are tons of other solution but you got the idea. I hope that's what you're looking for.

With those solution you can manually trigger your endpoint and change whatever you want in your application.

  • Related