What is the correct way of communicating (passing strings) between two different python scripts?
I have a ui.py script which utilizes PySide6 to generate a GUI, and I have another bot.py script which listens discord/telegram conversations and catching some keywords using async functions. Both scripts are at the same directory.
I have put Asyncio event loop code in my bot.py file to a function named runscript(), and using multiprocessing.Process from ui.py I run that function after I click a PySide6 QPushButton.
So the issue here is I want to display that keywords bot.py catches in my GUI so I need to pass that strings to ui.py (there will be need of passing strings the other way -from ui.py to bot.py- in the future) but I don't know how to this. I have tried multiprocessing.Pipe but that blocks my code because script fetches messages from discord/telegram when a new message arrives (using Asyncio) and I can not wait that to happen.
#bot.py
# do other stuff above here
@discord_client.event
async def on_message(message):
if message.channel.id in discord_channel_list:
discord_message = message.content
selected_symbol = message_analyzer(discord_message)
print(selected_symbol)
async def discord_connection():
await discord_client.start(discord_token)
def runscript():
connection = asyncio.get_event_loop()
connection.create_task(binance_connection())
connection.create_task(discord_connection())
connection.create_task(telegram_connection())
connection.create_task(connection_check())
try:
connection.run_forever()
except KeyboardInterrupt:
print("\nShutting down...")
except:
print("\nWARN! Shutting down...")
For example I need to get value of selected_symbol and transfer it to the ui.py
#ui.py
import bot
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.start_button = QPushButton("Start")
self.start_button.clicked.connect(self.run)
def run(self):
bot_process = Process(target=bot.runscript)
bot_process.daemon = True
bot_process.start()
What is the correct way to achieve this? Thanks in advance.