MacBook Pro sleeps randomly on the train My MacBook Pro Retina (2014) running 10.12.3 has a strange behavior on the train - while I'm actually using it, it goes to sleep and the only way to wake it up is to close the lid and reopen it. 
This happens when the mac is on battery power and on the train - doesn't happen when I'm in an office. 

As instructed by https://discussions.apple.com/thread/3428817?tstart=0 , I ran pmset -g pslog in a terminal, and this is the log that I got after a few times of this random sleep happening:

pmset is in logging mode now. Hit ctrl-c to exit.
2017-04-24 08:35:17 -0700 IOPSNotificationCreateRunLoopSource
Now drawing from 'Battery Power'
 -InternalBattery-0 (id=5046371)    84%; discharging; (no estimate) present: true
2017-04-24 08:36:10 -0700 IOPSNotificationCreateRunLoopSource
 -InternalBattery-0 (id=5046371)    83%; discharging; 2:15 remaining present: true
2017-04-24 08:36:10 -0700 com.apple.system.powersources.timeremaining
2017-04-24 08:36:10 -0700 com.apple.system.powersources.percent
2017-04-24 08:36:10 -0700 com.apple.system.powersources

2017-04-24 08:37:00 -0700 IORegisterForSystemPower: ...Sleeping...
2017-04-24 08:37:08 -0700 com.apple.system.powersources.timeremaining
2017-04-24 08:37:08 -0700 IOPSNotificationCreateRunLoopSource
 -InternalBattery-0 (id=5046371)    83%; discharging; (no estimate) present: true
2017-04-24 08:37:08 -0700 com.apple.system.powersources

2017-04-24 08:37:08 -0700 IORegisterForSystemPower: ...HasPoweredOn...
  Wake Reason = XHC1
  wakeType = HID Activity

2017-04-24 08:37:08 -0700 IORegisterForSystemPower: ...Sleeping...
2017-04-24 08:37:12 -0700 com.apple.system.powersources

2017-04-24 08:37:12 -0700 IORegisterForSystemPower: ...HasPoweredOn...
  Wake Reason = XHC1
  wakeType = HID Activity

2017-04-24 08:37:12 -0700 IORegisterForSystemPower: ...Sleeping...
2017-04-24 08:37:14 -0700 com.apple.system.powersources

2017-04-24 08:37:15 -0700 IORegisterForSystemPower: ...HasPoweredOn...
  Wake Reason = XHC1
  wakeType = HID Activity

2017-04-24 08:37:15 -0700 IORegisterForSystemPower: ...Sleeping...
2017-04-24 08:37:19 -0700 com.apple.system.powersources

2017-04-24 08:37:20 -0700 IORegisterForSystemPower: ...HasPoweredOn...
  Wake Reason = XHC1
  wakeType = HID Activity
^C


Does anyone have any idea why this is happening, and what I can do to prevent it? I'd hate to have to service it.
More than likely, the Reed switch1 that detects when the lid is open/closed is momentarily making contact and sending your MacBook into sleep/hibernation mode. It could be faulty. 

This YouTube video shows a MBP going to sleep when a magnet is applied to the area where the switch is located.

It's happening on the train because there is enough movement or bumps in the ride to cause the switch to close.  Closing and opening the lid "resets" the switch which then sends the signal to wake up.  Normally, these switches are pretty robust and movement like that of a vehicle isn't enough to to trip them, but I have seen defective ones that would fail by simply turning the machine upside down (Dell, not Apple).  That said, in over 25 years in IT, I can count the number of times on one hand I have seen this type of symptom.

If you still have Apple Care, take a video of the MacBook going to sleep on the train and how you wake it back up.  Take the video and the MacBook to Apple and have them fix the issue for you.



1 Wikipedia:  Reed switch The Reed switch is an electrical switch operated by an applied magnetic field