Hollywood got it wrong. The highly intelligent machines that will be unleashed in the near future won’t be coming for our lives. They’ll be coming for our jobs.

Being rendered obsolete by technology has been a concern among the flesh-and-blood set for hundreds of years — cars put many in the horse industry out of work, for example — but the speed and types of recent advances are about to give the issue an exceptional urgency.

Previously, it was repetitive blue-collar jobs that were at risk, such as those in manufacturing. In the near future, however, the leaps in artificial intelligence will soon make it possible for machines to do all sorts of jobs, including those that require thinking skills we once believed beyond the reach of machines.

Elements of this brave new world are laid out in “Homo Deus: A Brief History of Tomorrow” by Yuval Noah Harari, an Oxford-educated historian and professor at the Hebrew University of Jerusalem.

“I think we should be worried, and worried now,” Harari tells The Post. “Just 20 percent unemployment can cause political and social upheaval.”

In recent centuries, we have managed to rein in three huge obstacles that have stymied progress for centuries: famine, war and plague. But in the upcoming decades, one of the crucial questions will be what we humans will do for a living, as artificial intelligence speeds towards levels once reserved for science fiction.

A 2013 study by Oxford economists Carl Benedikt Frey and Michael Osborne concluded (using a sophisticated algorithm, of course) that some 47 percent of US jobs were at high risk from automation in the next 20 years. The economists posited that it was a near certainty that human telemarketers, insurance underwriters, security guards and other fields would vanish. Even sports referees could be headed for the historical dust bin.

Another research report issued in 2015 by McKinsey Global Institute, a business think tank, found that 95 percent of jobs should be safe until 2020, but after that, technology will change the landscape rapidly, with many employees’ duties moving to automation. The study found that 45 percent of work activities could be automated, including 20 percent of the responsibilities handled by the world’s obscenely compensated CEOs, such as analyzing operations data.

It might be a few years yet before your company is run by a machine, but the transition in other lower-paying fields is right around the corner.

One of the most vulnerable jobs is truck driver. The estimated 1 million American long-haul truckers will soon be replaced by self-driving vehicles that never need to sleep or stop to wolf down a greasy burger. Last year, Uber bought a self-driving startup called Otto. A few months later, one of its trucks made the first driverless delivery, shuttling 50,000 cans of beer 120 miles from Fort Collins to Colorado Springs.

It might be a few years yet before your company is run by a machine, but the transition in other lower-paying fields is right around the corner.

The outlook is equally bleak for the 8 million Americans working as salespeople or cashiers. Last year, Amazon opened an 1,800-square-foot store in Seattle with no cashiers or lines. Customers can simply grab the items they want off the shelf and walk out. Sensors track their purchases and charge the customers via their Amazon accounts after they leave the store.

Considering a career in the military? Human soldiers will likely be replaced by deadly robots and drones.

“Human soldiers murder, rape and pillage, and even when they try to behave themselves, they all too often kill civilians by mistake,” Harari writes.

The robotic killing machines could be programmed with “ethical algorithms” that will force them to strictly conform to the rules of the battlefield. And if they’re captured, they can’t be tortured, held hostage or coerced to reveal any of their nation’s secrets.

Government bureaucrats could also be endangered. A recent report from Reform, a right-leaning think tank, suggested that about 90 percent of British civil servants have jobs so pointless, they could be replaced by a machine. Transitioning to robots could save the government $8 billion per year.

Even a high-paying career such as medical doctor, previously considered safe from cold, faceless automation, is in jeopardy. A recent experiment found that a computer algorithm correctly diagnosed 90 percent of lung-cancer cases presented to it, outperforming a human physician by 40 percent.

“It won’t be all doctors,” Harari says. “If you research cures for cancer, you’re safe, but if you’re a general practitioner [who diagnoses diseases], this is something that AI will do much better than most human doctors. The GP is going to be extinct.”

Algorithms capable of instantaneously sifting millions of legal precedents could someday replace lawyers. And it’s conceivable that a machine could one day scan brains, serving as an infallible lie detector. Criminals will be easily proven guilty, helping to render not only lawyers, but also judges and detectives, obsolete.

Schools and teachers may also go the way of the dodo. Children will receive their lessons from sophisticated AI, possibly contained within a smartphone. Gone will be the days of 30 kids sitting in a room being tutored by various teachers specializing in different subjects.

“Companies are working on an AI teacher that is adapted to the strengths and weaknesses of the individual child,” Harari says. “Most schools will disappear. It will be much more similar to medieval apprenticeship. You’ll get instruction on everything from a single source.”

Even art, once the exclusive product of humans plumbing their souls, is being encroached upon by machines. David Cope, a University of California at Santa Cruz musicology professor, created a computer program called Experiments in Musical Intelligence designed to write chorales in the style of Bach. The tunes were played for an enthusiastic music festival audience, but when the source of the composition was revealed, some of that enthusiasm turned to anger and disbelief.

Cope later created another program capable of composing poetry. The algorithm contributed to a 2011 collection called “Comes the Fiery Night: 2,000 Haikus Written by Man and Machine.” (The book does not reveal who wrote what.)

This disruption in the workforce will likely come with challenges and dangers yet unseen in human history, not the least of which is the creation of a massive new stratum of society that Harari terms the “useless class.” These will be those citizens “devoid of any economic, political or even artistic value, who contribute nothing to the prosperity, power and glory of society.”

During the Industrial Revolution, farmers rendered obsolete could make the transition to unskilled factory jobs reasonably easily. In the future, it’s fairly unlikely the unemployed taxi driver is going to suddenly become a skilled software engineer.

Figuring out how to support the millions of out-of-work people could be one of the biggest economic challenges of the next century. Bill Gates has suggested taxing robotic workers just like humans. Tesla founder Elon Musk and others have advocated for a universal basic income — having the government hand over a certain sum each year to every citizen in order to keep the populace afloat.

A thornier issue the unemployed masses will face is a philosophical one.

“The harder challenge is how do people then have meaning, because a lot of people derive their meaning from their employment,” Musk said at the World Government Summit. “If you are not needed, if there is not a need for your labor, what’s the meaning?”

Harari predicts the “useless class” will occupy their days by immersing themselves in virtual-reality games. The chronically unemployed, Harari predicts, could also turn to drug use to pass the time — though one wonders if, in the future, with so many potentially dependent on chemical substances, less harmful drugs will be developed and legalized.

Meanwhile, the money that used to flow to workers will increasingly end up in the hands of the “tiny elite that owns the powerful algorithms,” Harari predicts, creating unprecedented social inequality.

There may even come a day when the algorithms themselves own much of the world’s wealth. (A health-related program is likely to be the most valuable.) It’s one small leap from today’s reality, in which much of the planet is already owned by non-human entities — namely nations and corporations.

That pattern will soon be upended, and workers will be forced to reinvent themselves multiple times within a lifetime, as technology continues to advance.

Not every worker will be tossed out on their behinds, of course. Some fields are unlikely to be automated. Archaeologists, for example, will continue to find work, because the job requires sophisticated pattern recognition that would be challenging to program into a machine, and the industry’s profits are so small that someone is unlikely to make the investment in an automated replacement.

Philosophers may also experience a windfall, as the new machine age will present unique problems that require human adjudication. “You’ll have to have practical answers to these kinds of philosophical questions,” Harari says.

Regardless of one’s chosen career path, we’re all going to have to be more flexible in the future. It used to be that humans spent the first part of our lives learning a skill that we then utilized in a career until we retired. That pattern will soon be upended, and workers will be forced to reinvent themselves multiple times, as technology continues to advance.