M
M
Max Payne2017-02-16 00:27:41
Python
Max Payne, 2017-02-16 00:27:41

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'))

test1.py
import sys
f = open('f.txt', 'w+')
f.write(sys.stdin.read()) # f.write(str(sys.stdin.read(), 'UTF-8')) тоже не работает
f.close()

But it doesn't work, which is not surprising. The file is always empty.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Max Payne, 2017-02-27
@YardalGedal

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

L
lega, 2017-02-16
@lega

https://docs.python.org/2/library/multiprocessing....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question