Photos media library on external hard drive
$ launchctl kill -TERM gui/$UID/com.apple.photoanalysisd


This command will stop the current instance of the photoanalysis daemon. Afterwards it is possible to eject the hard drive without any problems.