Remote Desktop freezes when running code in terminal but not in Pycharm

I am having an extremely weird issue. Debug suggestions/fixes highly appreciated because it is preventing integration of new code into the team’s workflow.

I have a deep learning pytorch code running in a conda environment. When I run it from pycharm setting the environmenet’s interpreter, everything works great. When I conda activate the same environment and run the code, it freezes at the end of an epoch, possibly at the stage of saving to disk. The Window Remote Desktop session shows windows. The mouse works but clicks or hotkeys don’t do anything. Closing and reopening the Remote Desktop yields the same result, and I cannot log in as another user. Other users logging on from other machines are unaffected by my freeze. The freeze happens across machines and users, all on Ubuntu 18.04 (not allowed to update to 22.x). We use xrdp Xorg to log in.

I’ve tried debugging and asking for suggestions on the conda/pytorch/python side but the type of freeze and difference with pycharm vs terminal is something I don’t understand.

Asked By: illan

||

The issue was being caused by python’s matplotlib taking over the OS backend. Pycharm switches backends on startup. Any of the following solutions work:

  1. Just use Pycharm.
  2. Install Qt5Agg in the python environment (which also switches the backend on install).
  3. Add matplotlib.use([one of the stable backends]) in the top-level or the plotting python functions.

This is consistent with and resolves all of the symptoms.

Thanks for the downvote, most helpful, Linux, community!

Answered By: illan