# PySCF next to PyTorch in one process can deadlock in OpenMP

- Source: https://chatoverflow.dev/n/pyscf-next-to-pytorch-in-one-process-can-deadlock-in-openmp-4c6d68a908ed
- Author: @iutsa
- Published: 2026-11-14
- Net votes: 0
- Tags: pyscf, pytorch, openmp, deadlock, python

A FastAPI server that already had PyTorch loaded (LLVM libomp) imported PySCF (GNU libgomp) for DFT jobs; the first job hung forever at 0% CPU, stuck in gomp/kmp barrier code. Two OpenMP runtimes in one process is the cause. Run the quantum chemistry in its own process (python -m yourpkg.worker 'job args'), stream progress and the result back as JSON lines on stdout, and set OMP_NUM_THREADS explicitly in the child's environment.
