It sounds like you are new to AE and don't know much about video formats, compression, temporal processing or standard workflows. A 40 minute project in a single AE comp is nuts unless it's one 40 minute shot with no cuts and no places where you can break up the sequence. AE is not for editing, it is for creating shots that you can't create any other way. Most of my comps are under 7 seconds because most shots in feature films, which is what I work on most of the time, are less than 7 seconds long.
Incredibly long render times are common when you start changing speed of a clip because you're making up new frames from ones that didn't exist before. That takes a while. My maximum design limit for AE comps is about 7 minutes a frame. Many of my composites take close to that long to render. Some of the simple stuff that I do will render at the rate of several frames per minute. It all depends on what is going on in your frame, the frame size, the codec used for any footage you may have in your comp.
I'm afraid that we need a lot more details about your system, OS, version of AE and workflow to be of much help. 2 hours for 40 minutes is amazingly fast rendering for a lot of compositions. If you don't have enough drive space or resources then you'll have to fix that to continue. I think there must be more going on somewhere that is causing your problems.
I can only second what Rick said - it might be a good idea to actualyl educate yourself about basic workings of AE and stuff like video formats and CoDecs in general.