1

I have a python script running on a vps. Now i just want to change 1 variable in the running script using my desktop computer.

What is the simplest way to that for a beginner?

alecxe
476k127 gold badges1.1k silver badges1.2k bronze badges
asked Mar 18, 2015 at 22:12
1
  • Simplest way is probably sockets Commented Mar 18, 2015 at 23:27

2 Answers 2

1

If I were a beginner, I would have my remote script periodically check the value of the variable in a text file. When I needed to update the variable, I would just ssh to my remote machine and update the text file.

answered Mar 19, 2015 at 1:20
Sign up to request clarification or add additional context in comments.

Comments

0

Using a text file that is polled at a regular interval is an easy way to go.

A more efficient and probably easier way is to register a signal handler in your python process that would force the process to reload the value in the text file when demanded rather than continuously polling. On linux you can use the kill command in the terminal to send the a signal after updating the file. This is actually probably simpler than implementing continuous polling.

import signal
import sys
import os 
print os.getpid()
def signal_handler(signal, frame):
 # open text file and check for new value
 print "value reset"
signal.signal(signal.SIGUSR1, signal_handler)

Then in Linux terminal to trigger the value to be reloaded you can do:

kill -SIGUSR1 pidprinted

If you wanted to get really fancy, you could register a signal handler to start pdb (python's debugger), inject the value into the running process, and continue, but I think doing the above is easiest.

answered Mar 19, 2015 at 1:44

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.