skip to Main Content

I’m programming a python robot in the telegram, but I have an error that is not resolved, the error is in the schedule

Traceback (most recent call last):
  File "C:Usersvini6AppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39site-packagesapschedulerschedulersbase.py", line 979, in _process_jobs
    executor.submit_job(job, run_times)
  File "C:Usersvini6AppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39site-packagesapschedulerexecutorsbase.py", line 71, in submit_job
    self._do_submit_job(job, run_times)
  File "C:Usersvini6AppDataLocalPackagesPythonSoftwareFoundation.Python.3.9_qbz5n2kfra8p0LocalCachelocal-packagesPython39site-packagesapschedulerexecutorspool.py", line 28, in _do_submit_job
    f = self._pool.submit(run_job, job, job._jobstore_alias, run_times, self._logger.name)
  File "C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.9_3.9.2544.0_x64__qbz5n2kfra8p0libconcurrentfuturesthread.py", line 169, in submit
    raise RuntimeError('cannot schedule new futures after '
RuntimeError: cannot schedule new futures after interpreter shutdown

5

Answers


  1. It’s bug or something of python 3.9.9. I also came across this issue. But it works well on python 3.7 and python 3.8. Not sure if any other python3.9.x works

    Update on 2022/02/11, this issue exists from python3.9 to python 3.10

    Login or Signup to reply.
  2. In case you are using python-telegram-bot, you might be missing an updater.idle() call after updater.start_polling()

    I reported a bug here, and got this solution as a reply, which fixed it for me. I had the very same error message, although it is a different package here. So leaving this for folks that come here, after searching for the above error message.

    Login or Signup to reply.
  3. You may face this issue if your code ends without a blocking loop.
    For instance, inside you main.py:

    # code start
    my_function_submitting_tasks_without_waiting()
    # end of file
    

    Instead you can do something like that

    # code start
    my_function_submitting_tasks_without_waiting()
    while True:
      pass
    # end of file
    

    But of course instead of "while True", you could use a "while not self._signal_stop:" inside your main class

    Login or Signup to reply.
  4. Faced the same problem while shutting down the scheduler, .shutdown(wait=False) worked fine.

    c = 0
    def tick():
        global c
        print(c)
        print('Tick! The time is: %s' %
              datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        # sleep(5)
        print('After sleep! The time is: %s' %
              datetime.now().strftime("%Y-%m-%d %H:%M:%S"))
        c += 1
        if c == 3:
            # sched.remove_job('my_job_id')
            sched.shutdown(wait=False)
    
    
    def main():
        sched.add_job(tick, 'interval', seconds=1,
                      next_run_time=datetime.now(),  # start immediately
                      id='my_job_id')
        sched.print_jobs()
        sched.start()
    
    Login or Signup to reply.
  5. Well, i have faced the same issue as of 28-Jun-2022 and landed here while searching.
    After some trial and error i have found some work around which works for me as of now.

    Solution 1 (trick)

    What we need is to stop the program to exit. So adding some pause at the end worked for me. Here the example is with BackgroundScheduler but any Non-blocking Scheduler will have same approach.

    import pause
    from apscheduler.schedulers.background import BackgroundScheduler
    
    scheduler = BackgroundScheduler()
    
    # your code goes here
    
    # start scheduler
    scheduler.start()
    
    # add pause in main
    pause.days(1) # or it can anything as per your need
    

    Solution 2

    Use BlockingScheduler instead of BackgroundScheduler

    from apscheduler.schedulers.blocking import BlockingScheduler
    
    scheduler = BlockingScheduler()
    
    # your code goes here
    
    scheduler.start()
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search