How OS detects external Hard-Drive. I mean what procedure or system calls i开发者_高级运维t makes to know about disk. Is there any way to automatically determine if External HDD got connected ?
(Answering the only question in your question.)
For Windows, you need to create a window and handle the WM_DEVICECHANGE message, specifically the DBT_DEVICEARRIVAL
event (which is sent automatically without having to register).
To do this from Python without creating a window, as far as I know the best you can do is to periodically test whether the root paths exist (once per second is probably sufficient, if you need to respond quicker than that Python is not going to work for you):
import os.path
for letter in "ABCDEFGHIJKLMNOPQRSTUVWXYZ":
drive_mounted[letter] = os.path.exists(letter + ":")
(Answering the non-questions in your question.)
The operating system detects USB/eSATA devices because the USB/eSATA controller on the motherboard will raise an interrupt on the CPU. The OS detects this interrupt and asks the controller about the device, installs any drivers necessary, activates the drivers, identifies a mount point (drive letter) and plays a sound effect.
(None of this has anything to do with Python, so I assume it also has nothing to do with this question.)
精彩评论