I am using a startup service that runs my code, but it has uncertain frame drops. The strange part is that this only occurs when using the service but not when executing the program normally.
Executing the program from command line executes smoothly without any frame drops.
Also, sometimes the code only executes when I disconnect and reconnect the camera after powering on to make it work with startup service.
Possibly it is due to the load, especially if it involves a hardware driver. I’m not sure of all of the details, but you could possibly add a 30-second delay to the startup via the systemd service file. Do you have the systemd service file (or any systemd file associated with this) that you can post here? And is that file located in “/etc/systemd/system/”, or is it located somewhere in “/lib/systemd/system/”?
Eventually you will find one of the files, and if in “/etc/systemd/system/”, directly edit the file, but if it is a symbolic link there pointing into “/lib/systemd/system/” then you will want to copy the file into “/etc/systemd/system/” before editing (files in “/etc/systemd/system/” are intended for editing, but if it is part of the system, then you want to leave the original and overwrite its content from “/etc”, which takes precedence). There should be somewhere you add a statement like this for a 30-second delay: ExecStartPre=/bin/sleep 30
Another possibility, if this is not it, is that priority is different between starting it on command line versus as a service. As a subtopic of that topic, if it runs as root (which normally it would do so when run as a systemd service), but runs as a regular user on command line (without sudo), then perhaps there are differences in permissions causing issues, or perhaps there are differences in process priority.