My Mac Book Pro switch between charge and not charge when running a long program
There's actually nothing you need to fix - it is intended behavior.
Consider that your laptop at idle is consuming (fictious numbers) 10W of power. You plugin a 61W power adapter, and it starts charging the battery at a rate up to 51W. I.e. this means that the power from the power adapter is used to power the computer primarily, and secondly to charge the battery.
Now you run a very power hungry program on your computer, and the computer starts to use 65W of power. Now all the power from the power adapter is used to power the computer, and the battery is also discharged slowly. This means that the status on the display will change from &quot;charging&quot; to &quot;not charging&quot;.
Your Python script most probably does different things at different times - some that take a lot of power and some that take less power. As a result, you'll see that some times the battery is being charged, and at other times it is not being chargd.