123
123

Reputation: 19

simplest way to make two python scripts talk to each other?

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?

Upvotes: 1

Views: 1657

Answers (2)

capturesteve
capturesteve

Reputation: 363

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.

Upvotes: 0

chishaku
chishaku

Reputation: 4643

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.

Upvotes: 1

Related Questions