def fork_happened2(): if uwsgi.i_am_the_spooler(): return print("worker %d is waiting for signal 100..." % uwsgi.worker_id()) uwsgi.signal_wait(100) print("worker %d received signal %d" % (uwsgi.worker_id(), uwsgi.signal_received())) print("fork() has been called [2] wid: %d" % uwsgi.worker_id())
def test_priority(self): uwsgi.signal_wait(17) print("Signal received.") with open(constants.LOGFILE, "r") as log: # Check logging ordering. loglines = [line.rstrip() for line in log] self.assertEqual(loglines, constants.ordered_tasks)
def test_priority(self): uwsgi.signal_wait(17) print("Signal received.") with open(spooler_priority_constants.LOGFILE) as log: # Check logging ordering. loglines = [line.rstrip() for line in log] self.assertEqual(loglines, spooler_priority_constants.ordered_tasks)
def setUp(self): try: remove(spooler_handlers.ghostpath) except OSError: # file does not exist pass spooler_handlers.controlled_task.spool(arg='alive', ghost='world') spooler_handlers.controlled_task.spool(arg='barbis') spooler_handlers.controlled_raw_task.spool(arg='alive', ghost='world') spooler_handlers.controlled_raw_task.spool(arg='barbis') for i in range(4): uwsgi.signal_wait(20) print("Signal received!")
def setUp(self): try: remove(spooler_handlers.ghostpath) except OSError: # file does not exist pass spooler_handlers.controlled_task.spool(arg="alive", ghost="world") spooler_handlers.controlled_task.spool(arg="barbis") spooler_handlers.controlled_raw_task.spool(arg="alive", ghost="world") spooler_handlers.controlled_raw_task.spool(arg="barbis") spooler_handlers.controlled_arguments_task.spool({"key": "value"}, 2, key1="value1") for i in range(5): uwsgi.signal_wait(20) print("Signal received!")
def signal_wait(self, signum): ''' Block the process/thread/async core until a signal is received. Use signal_received to get the number of the signal received. If a registered handler handles a signal, signal_wait will be interrupted and the actual handler will handle the signal. signum : Optional - the signal to wait for ''' return uwsgi.signal_wait(signum)
def start_scheduler(): try: s1.add_job(refresh_session_job, 'interval', seconds=RUN_TIME) s1.add_job(refresh_today_merchant_data_job, 'cron', minute="08,35,59", hour="0,1,6-23") s1.add_job(refresh_yesterday_merchant_data_job, 'cron', minute="01,04,15", hour="0") # s1.add_job(refresh_merchant_data_job, 'cron', minute="*/1", hour="0,1,7-23") s1.start() except (KeyboardInterrupt, SystemExit): pass except Exception as ex: LOGGER.exception(u"uwsgi的mule方式启动BackgroundScheduler失败,%s", ex) try: import uwsgi while True: # 阻塞uwsgi,避免一直启动mule sig = uwsgi.signal_wait() LOGGER.info(sig) except Exception as err: pass
def run_job(): job_id = request.values.get("id") a = scheduler.run_job(id=job_id) return jsonify({"job": str(a)}) @app.route("/vx/jobs", methods=['GET']) def get_all_jobs(): a = scheduler.get_jobs() return jsonify({"job": str(a)}) try: import uwsgi while True: sig = uwsgi.signal_wait() print(sig) except Exception as err: pass """ cron 参数 year (int 或 str) 年,4位数字 month (int 或 str) 月 (范围1-12) day (int 或 str) 日 (范围1-31 week (int 或 str) 周 (范围1-53) day_of_week (int 或 str) 周内第几天或者星期几 (范围0-6 或者 mon,tue,wed,thu,fri,sat,sun) hour (int 或 str) 时 (范围0-23) minute (int 或 str) 分 (范围0-59) second (int 或 str) 秒 (范围0-59) """
def wait_for_signal(): if uwsgi.worker_id() != 2: print("waiting for a signal...") uwsgi.signal_wait() print("signal %d received" % uwsgi.signal_received())
def wait(self, signal=None): if signal: uwsgi.signal_wait(self.signals[signal])