Python Forum
datasharing between two separated running scripts
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
datasharing between two separated running scripts
#1
hello everybody,

i need some help understanding what's best solution to share data between two running script.

this is my scenario:

i've a program named sensor.py that when started it creates three separated thread doing somestuff in background and saving result in a string variable json formatted.

this programs start automatically once OS starts.

everything working until here, now it gets worst......

on demand, i'd like to run a simple command line program (std input/output) able to read other program variables running in BG.

i know i can use socket but i dont want to use network, i read about Queue but i don't understand how to let it work with two separates scripts, i also read about named pipe (FIFO) but i understood it works with FileSystem (why i should i/o hdd when i have it in memory?).

thanks for any advice.
Reply
#2
You can run key-value store and exchange the data throughout it. E.g.,
install and run Redis server. Redis has python bindings and could be easily accessed from Python. It is quite fast and robust.
Now, one script, that is running in background, could store some data into Redis kv-store,
and the other one could get the data from it.
Reply
#3
(Dec-20-2018, 10:31 PM)scidam Wrote: You can run key-value store and exchange the data throughout it. E.g.,
install and run Redis server. Redis has python bindings and could be easily accessed from Python. It is quite fast and robust.
Now, one script, that is running in background, could store some data into Redis kv-store,
and the other one could get the data from it.

Redis is often referred as a data structures server. What this means is that Redis provides access to mutable data structures via a set of commands, which are sent using a server-client model with TCP sockets and a simple protocol. So different processes can query and modify the same data structures in a shared way.

it uses socket i dont want to use networking(think about a micro controller without a NIC)
Reply
#4
Then the question comes up, which micro controller and which bus systems/GIPOs the controller has.
The most micro controllers supports a serial connection. The most are based on 3.3V, the Arduino uses 5V.
To connect your micro controller to your PC, you need a signal level converter or you just buy from FTDI an USB2Serial device, which supports 3.3V.

If you want to program with Python on a micro controller, you should look here, for Chinese, here or you google for esp2866 and buy one device for 4$.

I've some developer boards from pycom. The benefit is the supported WiFi connection and the ability to get super small micro frameworks for flask, MQTT and other stuff.
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply
#5
(Dec-21-2018, 09:28 AM)DeaD_EyE Wrote: Then the question comes up, which micro controller and which bus systems/GIPOs the controller has.
The most micro controllers supports a serial connection. The most are based on 3.3V, the Arduino uses 5V.
To connect your micro controller to your PC, you need a signal level converter or you just buy from FTDI an USB2Serial device, which supports 3.3V.

If you want to program with Python on a micro controller, you should look here, for Chinese, here or you google for esp2866 and buy one device for 4$.

I've some developer boards from pycom. The benefit is the supported WiFi connection and the ability to get super small micro frameworks for flask, MQTT and other stuff.

Actually i'm using a raspberry with few I2C sensors, this data is sent to AWS IoT where i trigger some AWS Lambda doing some stuffs at the end of everything i can see them on a HTML page.

my goal is to ssh into the raspberry and using a second script to read those information before they are send out AWS that's why i don't want to use TCP socket i already have underlay networking for other purpose....


Anyway after some googling i think i found the solution using Unix Domain Sockets, same logic as TCP sockets but using internal communication( even if it looks like name pipe(FIFO))
Reply
#6
Using module posix_ipc you could share memory segments between the processes.
Reply
#7
(Dec-21-2018, 02:09 PM)Gribouillis Wrote: Using module posix_ipc you could share memory segments between the processes.

uhmmm this seems to be very close to what i was looking for.... i go to read it thanks m8!

i hope i can use it between different scripts opposite to multiprocessing queue
Reply
#8
Quote:i hope i can use it between different scripts opposite to multiprocessing queue
You can even use it between a python script and a completely different program. I used it to communicate between python and D programs.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How can histogram bins be separated and reduce number of labels printed on x-axis? cadena 1 894 Sep-07-2022, 09:47 AM
Last Post: Larz60+
  [SOLVED] [BeautifulSoup] Turn select() into comma-separated string? Winfried 0 1,125 Aug-19-2022, 08:07 PM
Last Post: Winfried
  Running python scripts from github etc pacmyc 7 3,731 Mar-03-2021, 10:26 PM
Last Post: pacmyc
  Running scripts and location of saved interpreted user-defined classes and functions leodavinci1990 3 2,542 Aug-25-2020, 03:43 AM
Last Post: micseydel
  How to print string multiple times separated by delimiter Mekala 1 1,913 May-23-2020, 09:21 AM
Last Post: Yoriz
  Running two scripts and more.... Brian_c 0 1,519 Mar-25-2020, 10:31 PM
Last Post: Brian_c
  Phyton code to load a comma separated csv file in to a dict and then in to a dB mrsenorchuck 2 2,681 Nov-29-2019, 10:59 AM
Last Post: mrsenorchuck
  can concatenated pickles be separated? Skaperen 0 1,352 Jul-29-2019, 06:35 PM
Last Post: Skaperen
  string agg separated by comma shyamal_kesh 1 2,122 Nov-23-2018, 12:57 PM
Last Post: Larz60+
  running two python scripts pythonper 1 2,616 Mar-14-2018, 06:57 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020