Compiling with Scheduler, How to stop all threads/schedules to terminate .exe?
- Dominant language
- Python
- Stars
- 12.3k
- Forks
- 999
- PR merge metrics
- No merged PRs in 30d
Description
Hello and goodday to you
I have created a .exe using scheduler and after compiling,
when the program is told to shut down it still hangs/remains in the background.
I'm thinking there is a bug as when I check jobs, they all show as cleared, but also likely its user error on my part..
So onto explaining...
I've removed scheduling out of the equation and then it shuts down as expected.
These are the commands im trying to shut down everything with.
```
running = False
stop_run_continuously.set()
stop_run_continuously.clear()
schedule.clear()
TPClient.disconnect()
Timer.cancel()
```
---
This is how I am starting the schedules
```
for scheduleFunc in [(disk_usage, "Update Interval: Hard Drive"),
(get_ip_loop, "Update Interval: Public IP"),
(check_number_of_monitors, "Update Interval: Active Monitors"),
(get_windows_update, "Update Interval: Active Windows"),
(vd_check, "Update Interval: Active Virtual Desktops")]:
interval = float(newsettings[scheduleFunc[1]])
if int(newsettings[scheduleFunc[1]]) > 0:
schedule.every(interval).seconds.do(scheduleFunc[0])
print(f"{scheduleFunc[1]} is now {interval}")
else:
print(f"{scheduleFunc[1]} is TURNED OFF")
```
---
I am also utilizing the code below which I acquired from [here](https://schedule.readthedocs.io/en/stable/background-execution.html)
```
import threading
import time
import schedule
def run_continuously(interval=1):
"""Continuously run, while executing pending jobs at each
elapsed time interval.
@return cease_continuous_run: threading. Event which can
be set to cease continuous run. Please note that it is
*intended behavior that run_continuously() does not run
missed jobs*. For example, if you've registered a job that
should run every minute and you set a continuous run
interval of one hour then your job won't be run 60 times
at each interval but only once.
"""
cease_continuous_run = threading.Event()
class ScheduleThread(threading.Thread):
@classmethod
def run(cls):
while not cease_continuous_run.is_set():
schedule.run_pending()
time.sleep(interval)
continuous_thread = ScheduleThread()
continuous_thread.start()
return cease_continuous_run
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the run_continuously entry point and the background-execution example, then reproduce the reported shutdown behavior using the shown cease event, schedule.run_pending loop, and compiled executable. Done means the scheduler thread stops when shutdown is requested and the executable terminates without remaining in the background.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100