
Restore iPhoto health when import hangs
I have a hobby - photography.
For cataloging by chance, I use the regular Apple program called iPhoto.
This thing is not buggy, one way or another all the time trying to completely lose or damage the photo library, but for lack of good alternatives - you have to use it.
Recently I ran into a problem: the camera was incorrectly removed during import and, as a result, the “import” slider hung in iPhoto and the program heroically refused to

exit correctly: Quick googling showed that the problem is very common, however, everyone is advised to do a “force quit” with subsequent recovery media libraries. Once I lost almost a hundred photographs like this, so I decided to look for other alternatives to the solution.
I admit that this text will help someone.
I will describe my steps in sequence, if suddenly someone notices errors in my thoughts - please correct.
After the reboot, the entire media library remained in a healthy state, it was not necessary to restore and try to revive it. All photos and videos found in "open streams and files" were in their places, including previews of all sizes and originals.
I hope this research will help someone next time to keep their photo library in order.
For cataloging by chance, I use the regular Apple program called iPhoto.
This thing is not buggy, one way or another all the time trying to completely lose or damage the photo library, but for lack of good alternatives - you have to use it.
Recently I ran into a problem: the camera was incorrectly removed during import and, as a result, the “import” slider hung in iPhoto and the program heroically refused to

exit correctly: Quick googling showed that the problem is very common, however, everyone is advised to do a “force quit” with subsequent recovery media libraries. Once I lost almost a hundred photographs like this, so I decided to look for other alternatives to the solution.
I admit that this text will help someone.
I will describe my steps in sequence, if suddenly someone notices errors in my thoughts - please correct.
- Repeated, deeper googling
Repeated search showed that this problem can occur due to 2 reasons: damage to the access rights on the disk and the incorrectly unmounted disk from which the import was carried out, as a result of which it remains in the list, but cannot be accessed. - Creating a backup
Just in case, I decided to make a copy of the library. A Time Machine copy was made about a week ago and there have been some changes since then. Simple file duplication failed. The system dirty cursed that the file is being used and refused to duplicate the library. Then it was decided to make a ZIP, but not through the Finder, but through the console. The process has been started - it's time to move on to other steps - Restoring access rights
Once they write that this may be a problem - you need to try. Analysis of the disk access rights utility and disk verification showed that everything is in order. Ok, move on. - Manual import cancellation
At this stage, the whole iPhoto was examined for the cherished “cancel import” button, but clicking on the “cancel” button in the interface yielded nothing. - Search for falsely mounted disks
Since I do not trust the disk utility GUI in this matter, the “diskutil list” spell was introduced in the console. The conclusion of the team showed that no anomalies were noticed and at first glance everything is fine - Finding the import process
My thoughts were simple - if you complete the import process, then iPhoto will most likely not close, but simply end the import. The likelihood of a crash, of course, persists, but it is quite small in comparison with the loss of images through the “force quit”.
Through the standard system monitoring utility, I tried to find the import process. Failed. At the same time, while studying the detailed information about the process, iPhoto discovered that the import is performed using one of the QuickTime components, however, restarting QuickTime did not give anything, besides the import was a separate thread in the process, and not a separate process, therefore, it was not possible to obtain a pid.
Interesting details surfaced at the same time - iPhoto kept several video files open, the source files of which had already been lost, which means that upon forced shutdown, these files would most likely be lost. Motivation increased - An attempt to replace the import
One more interface solution remained - to import a large file into iPhoto in order to start the import again. iPhoto turned out to be smarter and just launched parallel imports. - Pause / Restore
Since the hopes of preserving the music library (we are talking not only about files, but also about the structure) were rapidly disappearing, and by that time ZIP had been successfully created - I decided to try to pause the process with the help of a third-party file manager, and then run again. The rainbow wheel spun for a long time, but it did not lead to anything concrete. - A soft attempt to complete the application
On one of the forums it was read that if you send iPhoto a signal other than SIGKILL and the like, it still finishes correctly without damaging the library. Read - done, the following signals were sent to the application in direct order:- SIGCHLD (child status has changed)
- SIGSTP (stop signal generated from keyboard)
- SIGALRM (real-time timer expired)
At the last iPhoto, he turned the rainbow wheel for 7 seconds and collapsed.
After the reboot, the entire media library remained in a healthy state, it was not necessary to restore and try to revive it. All photos and videos found in "open streams and files" were in their places, including previews of all sizes and originals.
I hope this research will help someone next time to keep their photo library in order.