Using raw_input would not be appropriate in this case. You could (on UNIX) use signals and alarms in conjunction with raw_input in a simple case, but not recommended. First, do you need this to work cross platform? If so, you will find yourself having to develop some platform-dependent code. There is no magic bullet as of yet for handling terminals uniformly across platforms.
This post shows one UNIX way of handling the problem. Even though the aim in this post was different, it is entirely relevant.
This recipe, although somewhat dated, will give you an idea and starting point for what you will need.