I'm building a Python system with Linux
It takes too long to load
I'm going to load it first and approach it
So first, I'll run #python main.py
After loading, I set it to "while" and wait
When Python insert.py "Text Input" is executed, I want to send the text to main.py and get the output back
Is this possible?
Yes, it's possible.
I had a similar experience.
In my case, when I received a user's request from the WebServer, I executed the corresponding Python code and sent a response. However, it took a while for the Python code to go up on memory.
It happened because the code was executed only when there was a request, and all of the memory was deleted after writing Response.
The IPC concept was needed to solve this problem. InterProcess Communication can also share memory, but it is a technique used to maximize performance in places like C and Cpp. It can be solved like that, but the general solution is to use Socket a lot for IPC. I mean, the Server-Client model.
The problematic part should be returned to the server application at all times to the Damon state should be maintained.
It's the code I used before. It's an old code, so it might not fit right now.
Please keep that in mind .
..from multiprocessing.connection import Listener
from konlpy.tag import Kkma
from array import array
address = ('localhost', 65123)
password = b'1234'
listener = Listener(address, authkey=password)
#initialize
if __name__ == '__main__':
kkma = Kkma()
kkma.nouns('initializing')
print('main!')
while True:
conn = listener.accept()
print('connection accepted from', listener.last_accepted)
msg = conn.recv()
sendMessage = kkma.nouns(msg)
print(sendMessage)
conn.send(sendMessage)
conn.close()
© 2024 OneMinuteCode. All rights reserved.