[Python] How to inform another python file that the function completed in another program

Discussão em 'Python' iniciado por Stack, Maio 21, 2025.

  1. Stack

    Stack Membro Participativo

    I have two separate python programs running in jupyter notebook.

    Program 1 looks like this

    def doSomeCalculations():
    data_dic = doSomeCalculations()
    with open("data.pkl", 'wb') as f:
    pickle.dump(data_dic, f)


    Program 2 looks like this:

    import time
    import pickle
    import os
    while True:
    if time.time()-os.path.getmtime("data.pkl")<1:
    with open("data.pkl", 'rb') as f:
    data = pickle.load(f)
    break
    time.sleep(0.001)
    print("Running now")


    This is how, currently I am sending data between two files. First I inform the second program that the results are ready, then it reads the results in a file.

    How to improve this process? This is very inefficient, as I am reading the last modified time of the file every 1ms. Any better option?

    and I do this thing like 10 times in both files, not just once.

    Continue reading...

Compartilhe esta Página