Screenshot from 'The Martian' official trailer 20th Century Fox Spoiler alert if you haven't read "The Martian."

As Elton John once said, it's lonely out in space.

And it's even lonelier being stranded on a planet millions of miles from Earth, without communication, adequate food, or much hope of getting back home. That's the grim prospect Matt Damon's character faces in "The Martian," the upcoming film based on the novel by Andy Weir.

Damon plays NASA astronaut Mark Watney, a botanist on a fictional mission to Mars. Watney gets stranded on the Red Planet when a massive dust storm gravely injures him and forces his crewmates to escape, leaving him for dead. But Watney survives, and faces the daunting task of figuring out how to stay alive on an alien wasteland until he can be rescued.

Watney's technical prowess enables him to tackle the practical problems of getting enough water, oxygen, and food.

But perhaps the greatest hurdle he faces is psychological.

We talked to a NASA psychologist to find out if someone stranded on Mars could really make it without losing his or her mind.

"People have been able to keep it together mentally before" under extreme circumstances, such as being prisoners of war, Al Holland, a senior operational psychologist at NASA, told Business Insider. "We know that humans can be very resilient. One thing humans do very well is adapt."

One thing that's important for staying sane on journeys to space is real-time communication, which helps astronauts feel connected to friends and family. Thankfully for most of today's astronauts — including NASA astronaut Scott Kelly, who's spending a year on the International Space Station — communication is delayed by only a fraction of a second.

But on Mars, there would be a lag of about 20 minutes each way, which means a single exchange would take 40 minutes. In "The Martian," Watney faces the added difficulty of having to communicate with NASA using the camera on an old rover, which NASA can only use by pointing at letters and spelling out words. Talk about frustrating.

In the movie and book, Watney copes with the prospect of almost certain death using humor. At one point in the film when he's figuring out how he's going to survive, he says, "I'm gonna have to science the shit out of this."

A sense of humor is a huge asset for anyone, particularly for an astronaut, because it allows him or her to remain positive. Studies have shown that people use humor to cope with everything from losing their vision to having cancer.

Holland says it's also completely healthy for someone who is completely isolated to start having relationships with inanimate objects (think Wilson the volleyball in the film "Cast Away"). As for Watney, he develops a kind of relationship with the camera he uses to log his captivity on Mars.

Keeping focused on actively doing things is also important for avoiding depression like the kind that Mark Watney might have experienced (psychologists call this behavioral activation). For example, people who are kept in solitary confinement will do things like construct a house in their mind, brick by brick, Holland says. In Watney's case, he throws himself into solving each problem that presents itself on Mars, MacGuiver-style.

But when it comes to training astronauts in the real world, NASA prepares them to work in teams, not on their own. "It would be a very rare situation to have somebody left by themselves," says Holland, but "we also plan for the worst-case scenarios."

Although NASA trains its astronauts to deal with solitude, American astronauts still felt isolated when they flew to the Russian space station Mir in the 1990s, according to Holland. The predominant language was Russian, and communication with family on Earth wasn't reliable.

Astronauts have different strategies for keeping busy in space. Some read, some make things, and others focus more on their work. But astronauts going to Mars will likely have to be even more independent, more focused, and more resilient than those of today are.

The Martian premiers on Oct. 2.