Communicating between python programs

Hi frens

Easier to post here than stackoverflow
I want to have 2 python programs, one reads from telegram chat, and the other "pushes" that information to the other program which then analyses it periodically (checks price)

How should they communicate? Since I often reset the scripts and modify it might be cool to have some kind of storage, so I though maybe a text file between them.

Py1 writes to "STACK.txt", Py2 gets a trigger if the STACK file was moddified, reads it and ads it to it's own stack2.txt, and deletes the contents of STACK.txt.

STACK.txt would be opened as write only, so when py1 has a new payload, it would just write at the begining of the file again

is there a tutorial on this? Would it even work?

maybe use the watchdog module?

Attached: 1641685073350.jpg (1920x1920, 345.09K)

Other urls found in this thread:

en.wikipedia.org/wiki/Named_pipe
github.com/prakhar308/message-queues-in-python
twitter.com/NSFWRedditImage

use http

en.wikipedia.org/wiki/Named_pipe

you can either have them chat over an HTTP api (see flask) or you can have them leave messages to each other on the file system and you'd have to poll a file every so often (pretty dumb)

if you only need one way messaging you can just have the python script run a command on the operating system "script2.py"

github.com/prakhar308/message-queues-in-python

Have the scraper program write to a named pipe that the analysis program reads from. You can either create the pipe in bash, or python, then read from or write to it with whatever
# Scraper
res = telegrambot.get('blahlblahblah")
with open(pipe_name, 'w') as file:
file.write(res)

# Analysis program
with open(pipe_name) as file:
for line in file:
analyze(line)


Don't do anything like `while True` to constantly read the pipe or sleep or anything else, both are dumb. Just open it like a regular file and treat it like an iterator. it'll just werk.

forgot to add, `os.mkfifo` is the python function to create the pipe, in bash it's mkfifo. Just check the man page, it's pretty easy to figure out

Wow, a solution this simple exists and there were anons actually suggesting writing an entire HTTP fucking API or using a full-blown messaging queuing system like RabbitMQ to do this. Nu-Any Forums truly sucks.

I had to figure this out a year or so back when I needed to glue two programs together. API / task runner / long polling / redis etc were my first thought too, but turns out that unix tools are pretty nice and easy to use.

fucking retards

>t. academia retard making $12k a year as a (((TA)))

whoa python looks like that?

Named pipes are good like other anons said. You could also use sockets, that would also work. The general term for what you're asking is "inter-process communication", and you have a number of tools at your disposal for this

Why does the pipe need to be named? What's wrong with stdin / stdout?

>Easier to post here than stackoverflow
But here you won't get answers

you can just do metacoding and have script 2 wirte a python file with instructions.
#script 1
while True:
import sharedlib1 as s
...

Unix sockets
mmap to the same file

there are advantages to writing to an intermediary data store and you don't really lose anything. You don't need to use a message que library though. Just redis or something like that.

i'd love to let them interface with my C, if you know what i mean

Use udp

Pipe it hard, stuff that shit in until the submissive program is about to break. Force it to take all that data and work it like it was designed to do. Push it to the limit, pipe it hard af