Posted
over 5 years
ago
by
Srinithi
With celery, I have created listeners to Redis for getting all write events to Redis. Based on the events, I will trigger celery tasks to migrate data from Redis to DB.
I'm using the eventlet pool along with concurrency of 1000. Also
... [More]
, I'm having 5 celery queues for processing my data.
celery -A proj worker -l info -P eventlet -c 1000 -Q event_queue,vap_queue,client_queue,group_queue,ap_queue
Here, I'm facing the problem like, the listener is able to receive all the write events from Redis and workers are able to receive tasks from the listener. But, celery workers are delaying while processing huge number of data. (For example, I will be receiving 800 tasks per 10 seconds for each queue)
I have tried by increasing concurrency to higher values, changing the pool from eventlet to gevent and prefetch multiplier to 1. Still, My workers are delaying to complete a task.
Can anyone help to solve this? I'm new to celery actually :)
[Less]
|
Posted
over 5 years
ago
by
Airings
Here is a toy code of flask(1.1.1):
import eventlet
eventlet.monkey_patch()
from flask import Flask
import time
from flask_socketio import SocketIO
app = Flask(__name__)
socketio = SocketIO(async_mode='eventlet')
... [More]
socketio.init_app(app)
@app.route('/dummy_fun1')
def dummy_fun1():
print("this is dummy_fun1")
socketio.sleep(10)
return 'dummy_fun1'
@app.route('/dummy_fun2')
def dummy_fun2():
print("this is dummy_fun2")
socketio.sleep(8)
return 'dummy_fun2'
if __name__ == "__main__":
socketio.run(app, host='0.0.0.0', port=5566, debug=False)
Starting flask, then trying to access /dummy_fun1 in 2 different taps of chrome.
What I found is that the first access of /dummy_fun1 blocks the second access of /dummy_fun1. Because of threaded=True, I'd expect flask could serve these 2 accesses of the same url in parallel, but it didn't.
While flask does serve 2 accesses of different urls in parallel, in this case, /dummy_fun1 will not block /dummy_fun2 in any way.
Still learning Flask, don't quite understand why Flask behaves in this way, maybe it has nothing to do with Flask, really appreciate any advises to help me understand the underlying logic.
Update:
Try to be clear, so get rid of python threading, and leverage flask_socketio to run flask app with eventlet and make it in asnyc mode, but it still block the same accesses of one URL, and there is no blocking bewteen different URLs.
[Less]
|
Posted
over 5 years
ago
by
Seba Rossi
I'm currently trying to put in production a django project using nginx and gunicorn for the first time.
The project consist on a register page in wich the user access, fills a form and the data is used to make a request to
... [More]
another server to create a profile using the data taken from the form of my app.
To do such task i have the following libraries:
requests 2.22.0
gunicorn 20.0.4
eventlet 0.25.1 (with greenlet 0.4.15)
The project was entirely tested and functional in a testing enviroment inside an ubuntu 18.04 virtual machine.
Now the server in production is a Debian 10. Every web page of the project works corretly and so does the django admin page. The thing is that when i try to fill the form to actually register on the databese of the second server it returns the following error:
Environment:
Request Method: POST
Request URL: http://reg.rocstar.tv/register/customer/
Django Version: 2.2.7
Python Version: 3.7.5
Installed Applications:
['reg.apps.RegConfig',
'import_export',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/rocstar/register-page/register_page/reg/views.py" in CustomerRegister
63. r_login = requests.post("https://nb.mc.rocstar.tv/int/login", data = {"username" : CMS_user, "password" : CMS_pass}, allow_redirects = False)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/api.py" in post
116. return request('post', url, data=data, json=json, **kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/api.py" in request
60. return session.request(method=method, url=url, **kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/sessions.py" in request
533. resp = self.send(prep, **send_kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/sessions.py" in send
646. r = adapter.send(request, **kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/adapters.py" in send
449. timeout=timeout
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connectionpool.py" in urlopen
672. chunked=chunked,
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connectionpool.py" in _make_request
376. self._validate_conn(conn)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connectionpool.py" in _validate_conn
994. conn.connect()
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connection.py" in connect
394. ssl_context=context,
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/util/ssl_.py" in ssl_wrap_socket
370. return context.wrap_socket(sock, server_hostname=server_hostname)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/eventlet/green/ssl.py" in wrap_socket
438. return GreenSSLSocket(sock, *a, _context=self, **kw)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/eventlet/green/ssl.py" in __new__
76. *args, **kw
Exception Type: TypeError at /register/customer/
Exception Value: wrap_socket() got an unexpected keyword argument '_context'
The traceback shows an error when using requests command to access the login API of the second server wich is needed to then use the profile creation API.
I really don't understand wich is the problem because as i said is the first time i work with these tools. So any help is more than welcomed.
Thanks in advance
[Less]
|
Posted
over 5 years
ago
by
Seba Rossi
I'm currently trying to put in production a django project using nginx and gunicorn for the first time.
The project consist on a register page in which the user access, fills a form and the data is used to make a request to another
... [More]
server to create a profile using the data taken from the form of my app.
To do such task I have the following libraries:
requests 2.22.0
gunicorn 20.0.4
eventlet 0.25.1 (with greenlet 0.4.15)
The project was entirely tested and functional in a testing environment inside an ubuntu 18.04 virtual machine.
Now the server in production is a Debian 10. Every web page of the project works correctly and so does the Django admin page. The thing is that when I try to fill the form to actually register on the database of the second server it returns the following error:
Environment:
Request Method: POST
Request URL: http://reg.rocstar.tv/register/customer/
Django Version: 2.2.7
Python Version: 3.7.5
Installed Applications:
['reg.apps.RegConfig',
'import_export',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/rocstar/register-page/register_page/reg/views.py" in CustomerRegister
63. r_login = requests.post("https://nb.mc.rocstar.tv/int/login", data = {"username" : CMS_user, "password" : CMS_pass}, allow_redirects = False)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/api.py" in post
116. return request('post', url, data=data, json=json, **kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/api.py" in request
60. return session.request(method=method, url=url, **kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/sessions.py" in request
533. resp = self.send(prep, **send_kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/sessions.py" in send
646. r = adapter.send(request, **kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/adapters.py" in send
449. timeout=timeout
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connectionpool.py" in urlopen
672. chunked=chunked,
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connectionpool.py" in _make_request
376. self._validate_conn(conn)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connectionpool.py" in _validate_conn
994. conn.connect()
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connection.py" in connect
394. ssl_context=context,
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/util/ssl_.py" in ssl_wrap_socket
370. return context.wrap_socket(sock, server_hostname=server_hostname)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/eventlet/green/ssl.py" in wrap_socket
438. return GreenSSLSocket(sock, *a, _context=self, **kw)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/eventlet/green/ssl.py" in __new__
76. *args, **kw
Exception Type: TypeError at /register/customer/
Exception Value: wrap_socket() got an unexpected keyword argument '_context'
The traceback shows an error when using requests command to access the login API of the second server which is needed to then use the profile creation API.
I really don't understand which is the problem because as I said is the first time I work with these tools. So any help is more than welcomed.
[Less]
|
Posted
over 5 years
ago
by
Seba Rossi
I'm currently trying to put in production a django project using nginx and gunicorn for the first time.
The project consist on a register page in wich the user access, fills a form and the data is used to make a request to
... [More]
another server to create a profile using the data taken from the form of my app.
To do such task i have the following libraries:
requests 2.22.0
gunicorn 20.0.4
eventlet 0.25.1 (with greenlet 0.4.15)
The project was entirely tested and functional in a testing enviroment inside an ubuntu 18.04 virtual machine.
Now the server in production is a Debian 10. Every web page of the project works corretly and so does the django admin page. The thing is that when i try to fill the form to actually register on the databese of the second server it returns the following error:
Environment:
Request Method: POST
Request URL: http://reg.rocstar.tv/register/customer/
Django Version: 2.2.7
Python Version: 3.7.5
Installed Applications:
['reg.apps.RegConfig',
'import_export',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/rocstar/register-page/register_page/reg/views.py" in CustomerRegister
63. r_login = requests.post("https://nb.mc.rocstar.tv/int/login", data = {"username" : CMS_user, "password" : CMS_pass}, allow_redirects = False)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/api.py" in post
116. return request('post', url, data=data, json=json, **kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/api.py" in request
60. return session.request(method=method, url=url, **kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/sessions.py" in request
533. resp = self.send(prep, **send_kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/sessions.py" in send
646. r = adapter.send(request, **kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/adapters.py" in send
449. timeout=timeout
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connectionpool.py" in urlopen
672. chunked=chunked,
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connectionpool.py" in _make_request
376. self._validate_conn(conn)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connectionpool.py" in _validate_conn
994. conn.connect()
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connection.py" in connect
394. ssl_context=context,
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/util/ssl_.py" in ssl_wrap_socket
370. return context.wrap_socket(sock, server_hostname=server_hostname)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/eventlet/green/ssl.py" in wrap_socket
438. return GreenSSLSocket(sock, *a, _context=self, **kw)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/eventlet/green/ssl.py" in __new__
76. *args, **kw
Exception Type: TypeError at /register/customer/
Exception Value: wrap_socket() got an unexpected keyword argument '_context'
The traceback shows an error when using requests command to access the login API of the second server wich is needed to then use the profile creation API.
I really don't understand wich is the problem because as i said is the first time i work with these tools. So any help is more than welcomed.
[Less]
|
Posted
over 5 years
ago
by
Seba Rossi
I'm currently trying to put in production a django project using nginx and gunicorn for the first time.
The project consist on a register page in wich the user access, fills a form and the data is used to make a request to another server
... [More]
to create a profile using the data taken from the form of my app.
To do such task i have the following libraries:
requests 2.22.0
gunicorn 20.0.4
eventlet 0.25.1 (with greenlet 0.4.15)
The project was entirely tested and functional in a testing enviroment inside an ubuntu 18.04 virtual machine.
Now the server in production is a Debian 10. Every web page of the project works corretly and so does the django admin page. The thing is that when i try to fill the form to actually register on the databese of the second server it returns the following error:
Environment:
Request Method: POST
Request URL: http://reg.rocstar.tv/register/customer/
Django Version: 2.2.7
Python Version: 3.7.5
Installed Applications:
['reg.apps.RegConfig',
'import_export',
'crispy_forms',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles']
Installed Middleware:
['django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware']
Traceback:
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/django/core/handlers/exception.py" in inner
34. response = get_response(request)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
115. response = self.process_exception_by_middleware(e, request)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/django/core/handlers/base.py" in _get_response
113. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/rocstar/register-page/register_page/reg/views.py" in CustomerRegister
63. r_login = requests.post("https://nb.mc.rocstar.tv/int/login", data = {"username" : CMS_user, "password" : CMS_pass}, allow_redirects = False)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/api.py" in post
116. return request('post', url, data=data, json=json, **kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/api.py" in request
60. return session.request(method=method, url=url, **kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/sessions.py" in request
533. resp = self.send(prep, **send_kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/sessions.py" in send
646. r = adapter.send(request, **kwargs)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/requests/adapters.py" in send
449. timeout=timeout
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connectionpool.py" in urlopen
672. chunked=chunked,
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connectionpool.py" in _make_request
376. self._validate_conn(conn)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connectionpool.py" in _validate_conn
994. conn.connect()
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/connection.py" in connect
394. ssl_context=context,
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/urllib3/util/ssl_.py" in ssl_wrap_socket
370. return context.wrap_socket(sock, server_hostname=server_hostname)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/eventlet/green/ssl.py" in wrap_socket
438. return GreenSSLSocket(sock, *a, _context=self, **kw)
File "/home/rocstar/.local/share/virtualenvs/register-page-Z_TgQ-vY/lib/python3.7/site-packages/eventlet/green/ssl.py" in __new__
76. *args, **kw
Exception Type: TypeError at /register/customer/
Exception Value: wrap_socket() got an unexpected keyword argument '_context'
The traceback shows an error when using requests command to access the login API of the second server wich is needed to then use the profile creation API.
I really don't understand wich is the problem because as i said is the first time i work with these tools. So any help is more than welcomed.
[Less]
|
Posted
over 5 years
ago
by
Amadan
I need to start a server in one thread, a value producer in another thread (impersonated here by mock_producer), and the server's background thread is supposed to take each value from the queue and emit it to the client. At
... [More]
the same time, the WSGI server should serve the index.html when requested. Here's the best attempt so far:
# pip install eventlet python-socketio
from threading import Thread
from Queue import Queue
import eventlet
import socketio
def mock_producer(queue):
import time
import itertools
for count in itertools.count():
queue.put(count)
time.sleep(5)
def background():
while True:
if not queue.empty():
value = queue.get()
sio.emit('value', value);
sio.sleep(0.1)
sio = socketio.Server(logger=True)
app = socketio.WSGIApp(sio, static_files={
'/': 'index.html',
})
queue = Queue()
prod_thread = Thread(target=mock_producer, args=(queue,))
prod_thread.start()
ws_server = eventlet.listen(('', 5000))
ws_thread = sio.start_background_task(background)
eventlet.wsgi.server(ws_server, app)
with the accompanying toy index.html:
Test
The thing that bugs me is the sio.sleep(0.1) line. This obviously introduces a delay (however small) between an object being put into a queue, and the object being served to the client. But this doesn't work:
def background():
while True:
value = queue.get()
sio.emit('value', value);
The reason is, queue.get() blocks, which doesn't let the WSGI server serve the index.html page (which apparently happens on the same thread).
When I tried launching a new thread for the queue.get-emit loop (e.g. using Thread(target=background).start() instead of sio.start_background_task(background)), the debug output was claiming emit was happening, but nothing was reaching the client, so that was a bust, too.
Ideally, I'd like the code to be idle till either a request needs to be processed or a queue has a value, and react immediately to either.
Is there a way to write this cleanly?
NB: Unfortunately, stuck in Python 2 for this project due to a crucial dependency. I believe the only consequence is the import Queue from Queue line, but just in case.
[Less]
|
Posted
over 5 years
ago
by
Amadan
I need to start a server in one thread, a value producer in another thread (impersonated here by mock_producer), and the server's background thread is supposed to take each value from the queue and emit it to the client. At the same
... [More]
time, the WSGI server should serve the index.html when requested. Here's the best attempt so far:
# pip install eventlet python-socketio
from threading import Thread
from Queue import Queue
import eventlet
import socketio
def mock_producer(queue):
import time
import itertools
for count in itertools.count():
queue.put(count)
time.sleep(5)
def background():
while True:
if not queue.empty():
value = queue.get()
sio.emit('value', value);
sio.sleep(0.1)
sio = socketio.Server(logger=True)
app = socketio.WSGIApp(sio, static_files={
'/': 'index.html',
})
queue = Queue()
prod_thread = Thread(target=mock_producer, args=(queue,))
prod_thread.start()
ws_server = eventlet.listen(('', 5000))
ws_thread = sio.start_background_task(background)
eventlet.wsgi.server(ws_server, app)
with the accompanying toy index.html:
Test
The thing that bugs me is the sio.sleep(0.1) line. This obviously introduces a delay (however small) between an object being put into a queue, and the object being served to the client. But this doesn't work:
def background():
while True:
value = queue.get()
sio.emit('value', value);
The reason is, queue.get() blocks, which doesn't let the WSGI server serve the index.html page (which apparently happens on the same thread).
When I tried launching a new thread for the queue.get-emit loop (e.g. using Thread(target=background).start() instead of sio.start_background_task(background)), the debug output was claiming emit was happening, but nothing was reaching the client, so that was a bust, too.
Ideally, I'd like the code to be idle till either a request needs to be processed or a queue has a value, and react immediately to either.
Is there a way to write this cleanly?
NB: Unfortunately, stuck in Python 2 for this project due to a crucial dependency. I believe the only consequence is the import Queue from Queue line, but just in case.
[Less]
|
Posted
over 5 years
ago
by
justAskQuestion
The previous questions is here: The web-app is crashed when I deployed to Heroku but nothing is changed in the code
All configurations, please see the previous questions.
After I updated eventlet from 0.21.0 to 0.24.1, the error is
... [More]
happend below. Is eventlet 0.24.1 not compatible with any other configuration?
Or what problem is this?
$ heroku logs --tail --app main_project
(node:11006) ExperimentalWarning: The fs.promises API is experimental
��� heroku-cli: update available from 6.12.8 to 6.99.0-ec9edad
2019-11-26T13:17:40.891103+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/http/wsgi.py", line 387, in sendfile
2019-11-26T13:17:40.891105+00:00 app[web.1]: sent += os.sendfile(sockno, fileno, offset + sent, count)
2019-11-26T13:17:40.891107+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.891109+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.891111+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.891113+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.891115+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.891118+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.891120+00:00 app[web.1]: [Previous line repeated 912 more times]
2019-11-26T13:17:40.891176+00:00 app[web.1]: RecursionError: maximum recursion depth exceeded
2019-11-26T13:17:40.901002+00:00 app[web.1]: [2019-11-26 13:17:40 +0000] [9] [ERROR] Error handling request
2019-11-26T13:17:40.901005+00:00 app[web.1]: Traceback (most recent call last):
2019-11-26T13:17:40.901008+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 111, in handle_request
2019-11-26T13:17:40.901010+00:00 app[web.1]: resp.write_file(respiter)
2019-11-26T13:17:40.901012+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/http/wsgi.py", line 397, in write_file
2019-11-26T13:17:40.901013+00:00 app[web.1]: if not self.sendfile(respiter):
2019-11-26T13:17:40.901015+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/http/wsgi.py", line 387, in sendfile
2019-11-26T13:17:40.901017+00:00 app[web.1]: sent += os.sendfile(sockno, fileno, offset + sent, count)
2019-11-26T13:17:40.901019+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.901021+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.901023+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.901025+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.901027+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.901029+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.901031+00:00 app[web.1]: [Previous line repeated 912 more times]
2019-11-26T13:17:40.901067+00:00 app[web.1]: RecursionError: maximum recursion depth exceeded
2019-11-26T13:17:40.918234+00:00 app[web.1]: [2019-11-26 13:17:40 +0000] [9] [ERROR] Error handling request
2019-11-26T13:17:40.918238+00:00 app[web.1]: Traceback (most recent call last):
2019-11-26T13:17:40.918254+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 111, in handle_request
2019-11-26T13:17:40.918256+00:00 app[web.1]: resp.write_file(respiter)
2019-11-26T13:17:40.918258+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/http/wsgi.py", line 397, in write_file
2019-11-26T13:17:40.918260+00:00 app[web.1]: if not self.sendfile(respiter):
2019-11-26T13:17:40.918262+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/http/wsgi.py", line 387, in sendfile
2019-11-26T13:17:40.918264+00:00 app[web.1]: sent += os.sendfile(sockno, fileno, offset + sent, count)
2019-11-26T13:17:40.918265+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.918267+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.918269+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.918271+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.918273+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.918275+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.918277+00:00 app[web.1]: [Previous line repeated 912 more times]
2019-11-26T13:17:40.918278+00:00 app[web.1]: RecursionError: maximum recursion depth exceeded
2019-11-26T13:17:40.919734+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/imgs/sample.png" host=main_project.herokuapp.com request_id=05b57afb-de68-4a10-bc7d-acd752512b1c fwd="70.164.46.15" dyno=web.1 connect=1ms service=56ms status=503 bytes= protocol=https
2019-11-26T13:17:40.882508+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/js/ext/jquery-extensions.js" host=main_project.herokuapp.com request_id=be1c1bca-44c4-4220-b312-f9e722a5f3d9 fwd="70.164.46.15" dyno=web.1 connect=0ms service=29ms status=503 bytes= protocol=https
2019-11-26T13:17:40.901887+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/css/provider_video.css" host=main_project.herokuapp.com request_id=ee867669-b721-4e91-b0bf-151bc28f9364 fwd="70.164.46.15" dyno=web.1 connect=0ms service=52ms status=503 bytes= protocol=https
2019-11-26T13:17:40.778743+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/imgs/sample.svg" host=main_project.herokuapp.com request_id=691bdd85-3515-40d1-bb32-69294c87fbe8 fwd="70.164.46.15" dyno=web.1 connect=0ms service=22ms status=503 bytes= protocol=https
2019-11-26T13:17:40.892685+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/js/ext/jquery-ui.min.js" host=main_project.herokuapp.com request_id=df473aa6-df8d-4a27-9642-66be75b5838f fwd="70.164.46.15" dyno=web.1 connect=1ms service=42ms status=503 bytes= protocol=https
2019-11-26T13:17:40.842326+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/js/ext/jquery.min.js" host=main_project.herokuapp.com request_id=e40552ae-17bf-4778-93ed-55c58595b183 fwd="70.164.46.15" dyno=web.1 connect=0ms service=24ms status=503 bytes= protocol=https
2019-11-26T13:17:40.970404+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/js/ext/jquery-extensions.js" host=main_project.herokuapp.com request_id=a62c7b3e-f59f-4973-8776-b0fbd20412d5 fwd="70.164.46.15" dyno=web.1 connect=0ms service=19ms status=503 bytes= protocol=https
the Procfile is
web: gunicorn --worker-class eventlet -w 1 main:app
Please help this question, thank you very much.
[Less]
|
Posted
over 5 years
ago
by
justAskQuestion
The previous questions is here: The web-app is crashed when I deployed to Heroku but nothing is changed in the code
All configurations, please see the previous questions.
After I updated eventlet from 0.21.0 to 0.24.1
... [More]
, the error is happend below. Is eventlet 0.24.1 not compatible with any other configuration?
Or what problem is this?
$ heroku logs --tail --app main_project
(node:11006) ExperimentalWarning: The fs.promises API is experimental
��� heroku-cli: update available from 6.12.8 to 6.99.0-ec9edad
2019-11-26T13:17:40.891103+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/http/wsgi.py", line 387, in sendfile
2019-11-26T13:17:40.891105+00:00 app[web.1]: sent += os.sendfile(sockno, fileno, offset + sent, count)
2019-11-26T13:17:40.891107+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.891109+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.891111+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.891113+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.891115+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.891118+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.891120+00:00 app[web.1]: [Previous line repeated 912 more times]
2019-11-26T13:17:40.891176+00:00 app[web.1]: RecursionError: maximum recursion depth exceeded
2019-11-26T13:17:40.901002+00:00 app[web.1]: [2019-11-26 13:17:40 +0000] [9] [ERROR] Error handling request
2019-11-26T13:17:40.901005+00:00 app[web.1]: Traceback (most recent call last):
2019-11-26T13:17:40.901008+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 111, in handle_request
2019-11-26T13:17:40.901010+00:00 app[web.1]: resp.write_file(respiter)
2019-11-26T13:17:40.901012+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/http/wsgi.py", line 397, in write_file
2019-11-26T13:17:40.901013+00:00 app[web.1]: if not self.sendfile(respiter):
2019-11-26T13:17:40.901015+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/http/wsgi.py", line 387, in sendfile
2019-11-26T13:17:40.901017+00:00 app[web.1]: sent += os.sendfile(sockno, fileno, offset + sent, count)
2019-11-26T13:17:40.901019+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.901021+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.901023+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.901025+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.901027+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.901029+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.901031+00:00 app[web.1]: [Previous line repeated 912 more times]
2019-11-26T13:17:40.901067+00:00 app[web.1]: RecursionError: maximum recursion depth exceeded
2019-11-26T13:17:40.918234+00:00 app[web.1]: [2019-11-26 13:17:40 +0000] [9] [ERROR] Error handling request
2019-11-26T13:17:40.918238+00:00 app[web.1]: Traceback (most recent call last):
2019-11-26T13:17:40.918254+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base_async.py", line 111, in handle_request
2019-11-26T13:17:40.918256+00:00 app[web.1]: resp.write_file(respiter)
2019-11-26T13:17:40.918258+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/http/wsgi.py", line 397, in write_file
2019-11-26T13:17:40.918260+00:00 app[web.1]: if not self.sendfile(respiter):
2019-11-26T13:17:40.918262+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/http/wsgi.py", line 387, in sendfile
2019-11-26T13:17:40.918264+00:00 app[web.1]: sent += os.sendfile(sockno, fileno, offset + sent, count)
2019-11-26T13:17:40.918265+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.918267+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.918269+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.918271+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.918273+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 32, in _eventlet_sendfile
2019-11-26T13:17:40.918275+00:00 app[web.1]: return os.sendfile(fdout, fdin, offset, nbytes)
2019-11-26T13:17:40.918277+00:00 app[web.1]: [Previous line repeated 912 more times]
2019-11-26T13:17:40.918278+00:00 app[web.1]: RecursionError: maximum recursion depth exceeded
2019-11-26T13:17:40.919734+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/imgs/sample.png" host=main_project.herokuapp.com request_id=05b57afb-de68-4a10-bc7d-acd752512b1c fwd="70.164.46.15" dyno=web.1 connect=1ms service=56ms status=503 bytes= protocol=https
2019-11-26T13:17:40.882508+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/js/ext/jquery-extensions.js" host=main_project.herokuapp.com request_id=be1c1bca-44c4-4220-b312-f9e722a5f3d9 fwd="70.164.46.15" dyno=web.1 connect=0ms service=29ms status=503 bytes= protocol=https
2019-11-26T13:17:40.901887+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/css/provider_video.css" host=main_project.herokuapp.com request_id=ee867669-b721-4e91-b0bf-151bc28f9364 fwd="70.164.46.15" dyno=web.1 connect=0ms service=52ms status=503 bytes= protocol=https
2019-11-26T13:17:40.778743+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/imgs/sample.svg" host=main_project.herokuapp.com request_id=691bdd85-3515-40d1-bb32-69294c87fbe8 fwd="70.164.46.15" dyno=web.1 connect=0ms service=22ms status=503 bytes= protocol=https
2019-11-26T13:17:40.892685+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/js/ext/jquery-ui.min.js" host=main_project.herokuapp.com request_id=df473aa6-df8d-4a27-9642-66be75b5838f fwd="70.164.46.15" dyno=web.1 connect=1ms service=42ms status=503 bytes= protocol=https
2019-11-26T13:17:40.842326+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/js/ext/jquery.min.js" host=main_project.herokuapp.com request_id=e40552ae-17bf-4778-93ed-55c58595b183 fwd="70.164.46.15" dyno=web.1 connect=0ms service=24ms status=503 bytes= protocol=https
2019-11-26T13:17:40.970404+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=GET path="/static/js/ext/jquery-extensions.js" host=main_project.herokuapp.com request_id=a62c7b3e-f59f-4973-8776-b0fbd20412d5 fwd="70.164.46.15" dyno=web.1 connect=0ms service=19ms status=503 bytes= protocol=https
the Procfile is
web: gunicorn --worker-class eventlet -w 1 main:app
Please help this question, thank you very much.
[Less]
|