How do I get Caffeine-ng to work with Qemu (Keep host from suspending/sleeping while VMs are runnning)

Since I use IOMMU with my GPU along with other devices, sleeping the computer with one of these VMs running will crash the guest OSs. So Caffeine-ng seemed perfect for this use case!

The installation and configuration seems really basic. I get the system tray icon, and in preferences I put in /usr/bin/qemu-system-x86_64 in the list of processes. Even though I do most things through Libvirt and Virtual Machine Manager, this is the process that will come up once for each VM instance running.

But the computer will still sleep.

Even though this comes up at weird times in my logs, I seem to get this to come up quite often:

Feb 05 11:03:24 mbox caffeine.desktop[2014]: Failed to get name for process 9859
Feb 05 11:03:24 mbox caffeine.desktop[2014]: Traceback (most recent call last):
Feb 05 11:03:24 mbox caffeine.desktop[2014]:   File "/usr/lib/python3.10/site-packages/caffeine/utils.py", line 51, in get_processes
Feb 05 11:03:24 mbox caffeine.desktop[2014]:     process_name = get_process_name(num_pid).lower()
Feb 05 11:03:24 mbox caffeine.desktop[2014]:   File "/usr/lib/python3.10/site-packages/caffeine/utils.py", line 27, in get_process_name
Feb 05 11:03:24 mbox caffeine.desktop[2014]:     truncated_process_name = open("/proc/%s/status" % pid).readline()[6:-1]
Feb 05 11:03:24 mbox caffeine.desktop[2014]: FileNotFoundError: [Errno 2] No such file or directory: '/proc/9859/status'

I have no idea what process “9859” was (in this case), but it’s obviously never any of the Qemu processes. Since I could never get this to work, I end up just disabling suspending on my PC.

Anyone have any ideas?

I don’t know that Caffeine-NG is meant to work in a VM. It would be better to create an upstream issue and see what the developer says.

Caffeine-ng is running on the host, not in any guests. In fact, this thread has little to do with virtualisation. This is just my use case for it. Caffeine-ng is not keeping my PC awake, when I want that process to be Qemu.