I often do some scientific calculations with Python code. These are very CPU and at times RAM hungry. Usually my Xubuntu 16.04 GUI freezes for periods of time during such a task, which means I can't really use the machine during those calculations which is of course annoying. Mouse movement is stopped or extremely slowed down, as well as any other action. Is there a way to avoid this?
Do you have disk activity during those times? (ie. being ram hungry as you describe, it's page faulting regularly and needing to go to swap)
You may find altering the swappiness value may improve things a little (ie. the level of which it uses swap; normally 60(%). I'd suggest reducing to 10-30 but adjust for your hardware & requirements).
If you're not familiar with swappiness; refer
The gui slows when the system is overloaded; esp. if the page needed by a gui process isn't there (page-fault) and it has to wait for it to be reloaded from swap.
Yes you can have swap on ssd; pro's & con's (mostly pros in your case). I'd suggest a better choice maybe offloading/moving your python-processing to another [remote] machine you control from your device, or if you don't have another box, try and limit yourself to terminal apps that use less resources whilst your large python job(s) are running. The python job is your problem, not Xubuntu