FuturePhotonInitiative / PTCS

PIC Test Control Software
GNU General Public License v3.0
1 stars 0 forks source link

Queue hangs when running second time with an experiment that uses matplotlib #20

Closed abacef closed 5 years ago

abacef commented 5 years ago

Describe the bug running the queue a second time with at least one experiment that uses matplotlib in its script makes the UI freeze in the middle of the plot creation

Version of PTCS (or master commit hash) ae282291177d5d144dabceed7e808c59761ef1cd

To Reproduce Make sure an experiment exists that uses matplotlib

  1. add that experiment from the drop-down
  2. run the queue
  3. when the queue is finished, run it again. It will hang this time somewhere in the creation of a plot

Expected behavior it does not hang, the queue finishes.

Screenshots N/A

Desktop (please complete the following information):

Instruments Connected (if applicable and useful to include) N/A

Additional context This does not hang when running with PyCharm, but that is because in File > Settings > Tools > Python Scientific > Show plots in tool window is checked which makes python add an entry to the pythonpath which somehow does some weird importing with matplotlib which makes it not hang. Unchecking this box removes that path variable and makes it hang

abacef commented 5 years ago

Min repro:

Add this config to Configs/

{
  "name": "Min Repro",
  "experiment": [
    {
      "type": "PY_SCRIPT",
      "source": "MinRepro.py",
      "order": 1
    }
  ]
}

Also, add this script named MinRepro.py to the src/Scripts directory

import matplotlib.pyplot as plt

def main(data_map, experiment_result):
    plt.figure()

and run the code as said in the To Reproduce section of the issue.

abacef commented 5 years ago

When the PyCharm Show plots in tool window is checked, what it does is change the matplotlib backend. When this happens, the UI does not hang the second time. This is probably an issue with the default backend used (TKAgg). Since we have wxPython installed and it comes with its own renderer for some reason, I tried using the renderer and it fixes the issue (WXAgg)