Answer the question
In order to leave comments, you need to log in
How to implement such idea of multithreading?
The following idea arose:
We have the main process of the program, a child is created - in the parent process there is an endless loop that sends some data to the child without waiting for a response. How to implement it correctly? Which way to look?
I tried to implement this via Popen and PIPE (as stdin and stdout ) and send requests there via Popen.communicate, but it did not work, alas, since communicate waits for completion and displays the result, which I do not need.
PS Alas, I'm not as good at multithreading as I am at selecting tags for a question, so don't blame me.
UPD1
Thought up something like this:
main.py
import subprocess
p = subprocess.Popen(['python', 'test1.py'], stdin=subprocess.PIPE)
p.stdin.write(bytes('test1', 'UTF-8'))
import sys
f = open('f.txt', 'w+')
f.write(sys.stdin.read()) # f.write(str(sys.stdin.read(), 'UTF-8')) тоже не работает
f.close()
Answer the question
In order to leave comments, you need to log in
In general, I decided to abandon this idea and used sockets.
client.py receives data, processes and sends through the socket, server.py listens to the channel all this time.
UPD 08/11/2017 It
turned out to be even better to use multiprocessing.Manager
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question