flask-rq icon indicating copy to clipboard operation
flask-rq copied to clipboard

Can't let worker to handle with the job in queue

Open xiangzhaocheng12 opened this issue 4 years ago • 1 comments

Hello, Senior engineer.I got a problem that I could not handle my task when I put the put the job into the queue.

The code is as following:

import time
from flask import Flask
from flask_rq2 import RQ
app = Flask(__name__)
app.debug = True

app.config['RQ_OTHER_HOST'] = 'localhost'
app.config['RQ_OTHER_PORT'] = 6379
app.config['RQ_OTHER_PASSWORD'] = None
app.config['RQ_OTHER_DB'] = 0

rq = RQ(app)

@app.route('/doit2')
def doit2():
    echo = rq.get_queue().enqueue(takes_a_while, 'do it 2',
                                  name="low", connection="other")
    return 'Success2'


@app.route('/doit7')
def doit7():
    echo = rq.get_worker('low').work(True)
    print(echo)
    return 'Success7'

Web Server got a wrong when I request the http://127.0.0.1:5000/doit7:

ERRORS

  File "E:\envs\lingang-newapi\lib\site-packages\flask\app.py", line 1821, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "E:\envs\lingang-newapi\lib\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "E:\envs\lingang-newapi\lib\site-packages\flask\app.py", line 1950, in full_dispatch_request
    rv = self.dispatch_request()
  File "E:\envs\lingang-newapi\lib\site-packages\flask\app.py", line 1936, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "E:\pythonProjects\DeCheng\module_exercise\flask-rq\my_example\example\app.py", line 101, in doit7
    echo = rq.get_worker().work(True)
  File "E:\envs\lingang-newapi\lib\site-packages\rq\worker.py", line 526, in work
    self._install_signal_handlers()
  File "E:\envs\lingang-newapi\lib\site-packages\rq\worker.py", line 389, in _install_signal_handlers
    signal.signal(signal.SIGINT, self.request_stop)
  File "e:\programdata\anaconda3\lib\signal.py", line 47, in signal
    handler = _signal.signal(_enum_to_int(signalnum), _enum_to_int(handler))
ValueError: signal only works in main thread

Just like the example code,but I couldn't run it successfully. Thank you very much.

xiangzhaocheng12 avatar Sep 28 '20 02:09 xiangzhaocheng12

I refer to the Flask-SocketIO issue, but not usefull

Besides,I add the parameter threaded = True into app.run , But it not usefull either.

if __name__ == '__main__':
   app.run(threaded=True)

xiangzhaocheng12 avatar Sep 28 '20 03:09 xiangzhaocheng12

Seems like this is coming from rq itself. My guess is that it's been addressed since then, but if not then an issue should be reported there.

davidism avatar May 21 '24 15:05 davidism