0

Biting my teeth on a problem right now:

I would like to have a py (Slave.py - which is quite complex and already finished) start / run by another py (Master.py) in the Python IDLE several times, with Slave.py always being completely restarted. This means that all variables and imports etc. there are reinitialized with each start. Each time the Slave.py is restarted, different variable values ​​should be transferred from the Master.py to the Slave.py (the background is that the Slave.py requires a running time of 1 to 12 hours and the AI ​​does not remain stable over several runs with changed parameters.) I work in WIN10 with the Python IDLE and have Python 3.8.3.

Found something that at least executes the Slave.py in the IDLE:

(What is an alternative to execfile in Python 3?)

    with open ("Slave_01.py") as f:
       code = compile (f.read (), "Slave_01.py", 'exec')
       exec (code)

The problem remains for me to transfer variables from the Master.py to the Slave.py. I think you can write in the Master.py for example:

    global_vars = {"Wert1": "Ford", "Wert2": "Mustang", "Wert3": 1964}
    local_vars = {"Wert1": "VW", "Wert2": "Käfer", "Wert3": 1966}
    with open ("Slave.py") as f:
       code = compile (f.read (), "Slave.py", 'exec')
       exec (code, global_vars, local_vars)

My question now is how do you resume the variable values ​​in the Slave.py? Thanks for suggestions, how one could specifically write that.

quanturus
  • 1
  • 1
  • Have you checked out the `subprocess` library? – JonSG Apr 25 '21 at 22:09
  • Yes, I tried it with subprozess.popen. But that doesn`t work for me so well: The slave.py is not really running again, it seems that there are still dependencies. And the print-outputs in the IDLE are not as if the slave.py runs on its own. With open/exec the Slave.py starts every time new in the idle und the printouts in the IDLE are the same. And it's nice that the Master.py only continues when a run of the Slave.py is finished. All is runnung as I want. Only the transfer of variables are not clear. And actually I only need to pass one or two parameters that change with each run. – quanturus Apr 26 '21 at 10:52

0 Answers0