Answer the question
In order to leave comments, you need to log in
Is it possible in Linux to pass an instance of a class from one process to another and perform actions with it?
Actually, subject. As an example and explanation, I will cite the task that set him before me.
I have a working computer with Linux Mint on it. It runs a Python 3 script (let's call it check.py), which initiates two connections to switches on the network via telnet (done via pexpect), performs actions in each of them, collects information, and then leaves an interactive one in one of the connections, and the second is removed. I wanted to open a second terminal window, which would be interactive with a second connection.
Since I hid all the repetitive actions in classes, the code looked something like this:
from connections import connect_to_switch
switch1 = connect_to_switch('192.168.1.1')
switch2 = connect_to_switch('192.168.2.1')
#Дальше всякие действия с этими соединениями
del switch2
switch1.interact()
from connections import connect_to_switch
import subprocess
switch1 = connect_to_switch('192.168.1.1')
switch2 = connect_to_switch('192.168.2.1')
#Дальше всякие действия с этими соединениями
del switch2
subprocess.call("mate-terminal -e '/home/user/script.py {}'".format('192.168.2.1'), shell=True)
switch1.interact()
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question