Skip to content

Instantly share code, notes, and snippets.

@ishan1608
Last active May 2, 2024 16:28
Show Gist options
  • Save ishan1608/87cb762f31b7af70a867 to your computer and use it in GitHub Desktop.
Save ishan1608/87cb762f31b7af70a867 to your computer and use it in GitHub Desktop.
A python script to heat your computer so that your fingers can work upon your laptop in winter.
"""Heater
A program that spawns as much number of processes as there are CPUs on the computer.
This keeps the core temprature high.
I made this so that my fingers feel more comfortable while working on my laptop during winter.
Caution : An eye should be kept on the CPU temprature so that when it is getting too hot,
the prgoram needs to be killed; else it can damage the CPU.
Author : Ishan
Email : ishanatmuzaffarpur@gmail.com
"""
import multiprocessing
import sys
def round_robin_count():
while(True):
number = 0
if(number >= sys.maxsize):
number = 0
else:
number = number + 1
if __name__ == "__main__":
if len(sys.argv) == 2 and sys.argv[1] == '--about':
print(__doc__)
elif len(sys.argv) == 2 and sys.argv[1] == '--help':
print('Heater', 'USAGE: python3 ' + sys.argv[0] + ' [option]', sep='\n')
print('To read about.', 'python3 ' + sys.argv[0] + ' --about' ,sep=' ')
print('To see this help message.', 'python3 ' + sys.argv[0] + ' --help', sep=' ')
else:
process_count = 1
print('Heating up the CPU')
while(process_count <= multiprocessing.cpu_count()):
process_to_be_not_seen_again = multiprocessing.Process(target=round_robin_count)
process_to_be_not_seen_again.start()
process_count += 1
@yeetyboi56-deprecated
Copy link

epic this helps

@hacker1024
Copy link

Doesn't run on macOS 11.3.1 with Python 3.9.1:

Heating up the CPU
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 116, in spawn_main
    exitcode = _main(fd, parent_sentinel)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 125, in _main
    prepare(preparation_data)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 236, in prepare
    _fixup_main_from_path(data['init_main_from_path'])
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 287, in _fixup_main_from_path
    main_content = runpy.run_path(main_path,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 268, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 97, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/runpy.py", line 87, in _run_code
    exec(code, run_globals)
  File "/Users/hacker1024/Downloads/heater.py", line 37, in <module>
    process_to_be_not_seen_again.start()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/process.py", line 121, in start
    self._popen = self._Popen(self)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 224, in _Popen
    return _default_context.get_context().Process._Popen(process_obj)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/context.py", line 284, in _Popen
    return Popen(process_obj)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 32, in __init__
    super().__init__(process_obj)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_fork.py", line 19, in __init__
    self._launch(process_obj)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/popen_spawn_posix.py", line 42, in _launch
    prep_data = spawn.get_preparation_data(process_obj._name)
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 154, in get_preparation_data
    _check_not_importing_main()
  File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/spawn.py", line 134, in _check_not_importing_main
    raise RuntimeError('''
RuntimeError:
        An attempt has been made to start a new process before the
        current process has finished its bootstrapping phase.

        This probably means that you are not using fork to start your
        child processes and you have forgotten to use the proper idiom
        in the main module:

            if __name__ == '__main__':
                freeze_support()
                ...

        The "freeze_support()" line can be omitted if the program
        is not going to be frozen to produce an executable.

@ishan1608
Copy link
Author

ishan1608 commented May 11, 2021

@hacker1024 I never owned a macbook, so couldn't test it on mac os.
If you find a solution let me know, I'll update the gist. And if I find a solution that works. I'll update the gist here.

Update: As it turns out just wrapping the main code in if __name__ == '__main__': solves the problem.
For more context you can look at this comment https://stackoverflow.com/questions/61931669/python-multiprocessing-runtimeerror-an-attempt-has-been-made-to-start-a-new-pro#comment109560442_61931669

@TreWade1469
Copy link

How do you use it or like turn it on or control it or whatever

@ishan1608
Copy link
Author

@TreWade1469 I execute the python script and when I feel my fingers are warm enough, I kill the process using ctrl + c.

@TreWade1469
Copy link

How do you download it, and turn it on?

@ishan1608
Copy link
Author

@TreWade1469 Running a python script is a pretty basic step. (Not that I am assuming anything here).
But, if you don't know how to do that. May I please ask you not to run this script and rather first learn the basics of python first.
There are tons of tutorials/courses available on the internet.
Please go through them first as running this script could be dangerous and kill your device.
I don't want you to mistakenly harm your device.

@TreWade1469
Copy link

Ok thanks

@Speed3k-python
Copy link

Speed3k-python commented May 1, 2024

@ishan1608
Instead of
process_to_be_not_seen_again = multiprocessing.Process(target=round_robin_count)
process_to_be_not_seen_again.start()
Use:
if __name__ == "__main__":
process_to_be_not_seen_again = multiprocessing.Process(target=round_robin_count)
process_to_be_not_seen_again.start()

@ishan1608
Copy link
Author

@Speed3k-python That piece of code is already inside the if __name__ == "__main__": block.
What would adding another redundant condition do?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment