How to prevent a laptop from sleeping when the lid is closed while running a program
To prevent a laptop from sleeping when the lid is closed, you can use the Terminal command sudo pmset -a disablesleep 1. This will keep the laptop awake even when the lid is closed. Note that this may cause the laptop to heat up, so it's not recommended to close the lid and put it in a bag. To revert this setting, use the same command with 0 instead of 1.