'Jenkins - Continuous deployment for (non-stop running) single-file python application

I have made a simple telegram bot in Python. All code is in one .py file.

Trying to achieve "continues deployment" I installed Jenkins, and with the GitHub plugin, when Jenkins receives a GitHub push hook, it checks to see if the hook came from a GitHub repository which matches the Git repository defined in SCM/Git section of my job.

enter image description here

If they match, GitHub Plugin triggers my "build", which is a simple shell command:

python bot.py

The problem I have is that the bot is obviously running all the time. So when the next build is triggered, it remains on hold (pending), as it can not kill the previous process.

enter image description here

Therefore, I have to kill it myself if I want the building process to proceed.

So, is there any way for Jenkins to automatically stop the previous process and run the next one? In a web application for example you do "redeploy" and everything is fine, but what can I do for single-file applications?

Please feel free to suggest me best practices if my approach is completely wrong. Unfortunately I have not been able to find anything related to continues deployment for single-file python projects with Jenkins.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source