How do I pass a variable from one python script to another?

Viewed 55

I have two python scripts. I'll call them first.py and second.py. I know that this question has been answered many times, but they dont work for my context.

First.py - message is passed into the function called run

def run(message):
    split=message.split()
    word = split[0]
    _t = Thread(name="{}_Thread".format(word),target=_threader_,args=(word))
    _t.daemon = True
    _t.start()

def _threader_(word):
    while True: 
        if (_data from second.py == word):
            ##do stuff

        sleep(1)

Second.py

class First():
    def __init__(self,
                 _active=True,
                 _returnvalue=None):
        self._active = _active
        self._returnvalue = _returnvalue
        self._delay = 1
        self._t = Thread(target=self.Poll_data)
        self._t.daemon = True
        self._t.start()

    def Poll_data(self):
        while self._active:
            #_data is being assigned new variables in here
            _data = ...
            print(_data)
            sleep(self._delay)

First.py imports second.py so when I import first.py from second.py it throws errors.

I used to have the _data in the init of second.py but every time i accessed it from first.py it would return None (self._data = None in init)

How do I send the variable _data from second.py to the first.py threader. I have tried pickle but it is too slow as there is a latency in storing the file and sometimes i just get EOF errors.

Thanks

0 Answers
Related