简体   繁体   中英

Send values from one python script to another one already running

I'm trying to understand how I can develop a system that is made from two python script running in a linux box.

The first one starts on system boot and always run, basically connects to a MQTT server and wait for the other python script. The second one is called from the command line, doing some works and then pass some data, basically three strings, to the first one and than exits.

Which way is the "correct" one to be used in this situation to pass data from script two to script one?

There are multiple ways to accomplish this (blocking and non-blocking). Depending on your MQTT server you could use it in a pub/sub approach to pass the data from the temporary script to the running one.

If that is not possible another pub/sub server could be used as eg redis . Especially the pub/sub functionality of redis is very useful for this. redis is well supported in python.

Another more lightweight possibility is to use a First In First Out (FIFO) queue cf article on using fifos in python or blocking vs. non-blocking fifos

FIFOs are easy to use if both processes run on the same computer. redis would be preferable if both scripts run on different computers.

There are more complex packages for inter-process communication around, eg rabbitMQ , zeroMQ ,.. but they might be overkill for your use case...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM