Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8684987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:26:45+00:00 2026-06-12T22:26:45+00:00

I have a repeated python schedule task as following,which need to run getMyStock() every

  • 0

I have a repeated python schedule task as following,which need to run getMyStock() every 3 minutes in startMonitor():

from stocktrace.util import settings
import time, os, sys, sched
schedule = sched.scheduler(time.time, time.sleep)

def periodic(scheduler, interval, action, actionargs=()):
  scheduler.enter(interval, 1, periodic,
                  (scheduler, interval, action, actionargs))
  action(*actionargs)


def startMonitor():    
    from stocktrace.parse.sinaparser import getMyStock       

    periodic(schedule, settings.POLLING_INTERVAL, getMyStock)
    schedule.run( )

The questions are:

1.how could i cancel or stop the schedule when some user event comes?

2.Is there any other python module for better repeated scheduling?Just like java quartz?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:26:46+00:00Added an answer on June 12, 2026 at 10:26 pm

    Q1: scheduler.enter returns the event object that is scheduled, so keep a handle on that and you can cancel it:

    from stocktrace.util import settings
    from stocktrace.parse.sinaparser import getMyStock   
    import time, os, sys, sched
    
    class Monitor(object):
        def __init__(self):
            self.schedule = sched.scheduler(time.time, time.sleep)
            self.interval = settings.POLLING_INTERVAL
            self._running = False
    
        def periodic(self, action, actionargs=()):
            if self._running:
                self.event = self.scheduler.enter(self.interval, 1, self.periodic, (action, actionargs))
                action(*actionargs)
    
        def start(self):
            self._running = True
            self.periodic(getMyStock)
            self.schedule.run( )
    
        def stop(self):
            self._running = False
            if self.schedule and self.event:
                self.schedule.cancel(self.event)
    

    I’ve moved your code into a class to make referring to the event more convenient.

    Q2 is outside of the scope of this site.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following string repeated many times (about 10 times) <br /> <a
I have a streaming input which has repeated values. I can use any data
I have the following XML code. You will notice the tag Description is repeated,
I have a database from which I am trying to extract certain information. The
I have a program with a Mono-based C# client and a Python server, which
I'm programming in python. I have the data of the following form: (A, B,
I have repeated-measures data. I need to create a loop that will incrementally count
I have a database which consists of a graph. The table I need to
I have a table with a lot of repeated data that I'd like to
I have the same block of code repeated with two different variables. This block

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.