Skip to content

Instantly share code, notes, and snippets.

@ritwickdey
Last active May 2, 2026 14:55
Show Gist options
  • Select an option

  • Save ritwickdey/39fbd2a92ea60e4206f05961674ee8de to your computer and use it in GitHub Desktop.

Select an option

Save ritwickdey/39fbd2a92ea60e4206f05961674ee8de to your computer and use it in GitHub Desktop.
In case if laptop is not charging due to cold temperature
import multiprocessing
import os
def infinite_loop():
pid = os.getpid()
x = 0
print("This infinite loop runs on a separate process. pid:", pid)
while True:
x += 1
if __name__ == "__main__":
num_cores = multiprocessing.cpu_count()
processes = []
for _ in range(num_cores):
process = multiprocessing.Process(target=infinite_loop)
process.start()
processes.append(process)
try:
# Run the infinite loop on all cores
for process in processes:
process.join()
except KeyboardInterrupt:
# Terminate all processes on Ctrl+C
for process in processes:
process.terminate()
process.join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment