title: uWSGI process 17078 got Segmentation Fault
body: <p>I am trying to run a flask app as a service using uwsgi. But getting an error:</p>
  
  <blockquote>
    <p>uWSGI process 17078 got Segmentation Fault</p>
  </blockquote>
  
  <p>Here is what i tried:</p>
  
  <p><strong>manage.py</strong></p>
  
  <pre><code>from flask_script import Manager
  from flask_migrate import Migrate, MigrateCommand
  from whatsapp_api import ms_crm_whatsapp, db
  
  migrate = Migrate(ms_crm_whatsapp,db)
  manager = Manager(ms_crm_whatsapp)
  manager.add_command('db',MigrateCommand)
  </code></pre>
  
  <p>if <strong>name</strong> == '<strong>main</strong>':
         manager.run()</p>
  
  <p><strong>database.py</strong></p>
  
  <pre><code>from whatsapp_api import db
  from sqlalchemy.dialects.postgresql import JSON
  
  # print('db##############',db)
  class TempTable(db.Model):
      # print('TempTable')
      __tablename__ = 'crm_user_chat_data'
  
      id = db.Column(db.Integer, primary_key=True)
      name = db.Column(db.String())
      case_type = db.Column(db.String())
      sub_type = db.Column(db.String())
      number = db.Column(db.String())
      description = db.Column(db.String())
      crm_customer_id = db.Column(db.String())
      title = db.Column(db.String())
  
      def __init__(self,name,case_type,number,description,sub_type,crm_customer_id,title):
          print('inside __init__')
          self.name = name
          self.case_type = case_type
          self.number = number
          self.description = description
          self.sub_type = sub_type
          self.crm_customer_id = crm_customer_id
          self.title = title
  
      def __repr__(self):
          print('__repr__',__repr__)
          return '&lt;id {}&gt;'.format(self.id)
  </code></pre>
  
  <p><strong>whatsapp_api.py</strong></p>
  
  <pre><code>from flask import Flask, request, jsonify
  import time
  import requests
  import json
  import re
  from nltk.chat.util import Chat, reflections
  from flask_sqlalchemy import SQLAlchemy
  import psycopg2
  ms_crm_whatsapp = Flask(__name__)
  ms_crm_whatsapp.config["DEBUG"] = True
  ms_crm_whatsapp.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
  ms_crm_whatsapp.config["SQLALCHEMY_DATABASE_URI"] = 'postgresql://user:user_password@localhost:5432/db_name'
  db = SQLAlchemy(ms_crm_whatsapp)
  from database import TempTable
  con = psycopg2.connect("host=localhost dbname=db_name user=user password=user_password")
  cur = con.cursor()
  
  @ms_crm_whatsapp.route('/',methods=['GET','POST'])
  def home():
     return "&lt;h1&gt; Hello welcome to the world of Flask"
  </code></pre>
  
  <p>ms_crm_whatsapp.run(host='0.0.0.0' port=3000)</p>
  
  <p>I was running the app like <code>python3 manage.py</code></p>
  
  <p><strong>wsgi.py</strong></p>
  
  <pre><code>from whatsapp_api import ms_crm_whatsapp
  if __name__ == "__main__":
  ms_crm_whatsapp.run()
  </code></pre>
  
  <p>and in the terminal, I tried,</p>
  
  <pre><code> uwsgi --socket 0.0.0.0:3000 --protocol=http -w wsgi:ms_crm_whatsapp
  </code></pre>
  
  <p>in terminal i getting:</p>
  
  <blockquote>
    <p><strong>* Starting uWSGI 2.0.18 (64bit) on [Tue Nov  5 17:05:48 2019] <em></strong>
    compiled with version: 7.4.0 on 05 November 2019 10:27:46
    os: Linux-4.15.0-66-generic #75-Ubuntu SMP Tue Oct 1 05:24:09 UTC 2019
    nodename: lenovo-v330-kbir
    machine: x86_64
    clock source: unix
    pcre jit disabled
    detected number of CPU cores: 8
    current working directory: /home/user/python-environments/ms_crm_whatsapp_poc
    detected binary path: /home/user/python-environments/flask_venv/bin/uwsgi
    <strong></em> WARNING: you are running uWSGI without its master process manager <em></strong>
    your processes number limit is 30456
    your memory page size is 4096 bytes
    detected max file descriptor number: 1024
    lock engine: pthread robust mutexes
    thunder lock: disabled (you can enable it with --thunder-lock)
    uwsgi socket 0 bound to TCP address 0.0.0.0:3000 fd 3
    Python version: 3.6.8 (default, Oct  7 2019, 12:59:55)  [GCC 8.3.0]
    <strong></em> Python threads support is disabled. You can enable it with --enable-threads <em></strong>
    Python main interpreter initialized at 0x55f79717ce50
    your server socket listen backlog is limited to 100 connections
    your mercy for graceful operations on workers is 60 seconds
    mapped 72920 bytes (71 KB) for 1 cores
    <strong></em> Operational MODE: single process <em></strong>
    unable to load configuration from from multiprocessing.semaphore_tracker import main;main(4)
    /home/user/.local/lib/python3.6/site-packages/psycopg2/<strong>init</strong>.py:144: UserWarning: The psycopg2 wheel package will be renamed from release 2.8; in order to keep installing from binary please use "pip install psycopg2-binary" instead. For details see: <a href="http://initd.org/psycopg/docs/install.html#binary-install-from-pypi" rel="nofollow noreferrer">http://initd.org/psycopg/docs/install.html#binary-install-from-pypi</a>.
      """)
    !!! uWSGI process 19684 got Segmentation Fault !!!
    <strong></em> backtrace of 19684 <em></strong>
    uwsgi(uwsgi_backtrace+0x2a) [0x55f79555a3da]
    uwsgi(uwsgi_segfault+0x23) [0x55f79555a7c3]
    /lib/x86_64-linux-gnu/libc.so.6(+0x3ef20) [0x7f8abd3ddf20]
    /home/user/.local/lib/python3.6/site-packages/psycopg2/.libs/./libssl-c0c2ede4.so.1.0.2q(ssl3_cleanup_key_block+0xb) [0x7f8a81ae1cab]
    /home/user/.local/lib/python3.6/site-packages/psycopg2/.libs/./libssl-c0c2ede4.so.1.0.2q(ssl3_clear+0x16) [0x7f8a81adf5a6]
    /home/user/.local/lib/python3.6/site-packages/psycopg2/.libs/./libssl-c0c2ede4.so.1.0.2q(tls1_clear+0x9) [0x7f8a81aeb219]
    /usr/lib/x86_64-linux-gnu/libssl.so.1.1(SSL_new+0x3f2) [0x7f8abe9369e2]
    /home/user/.local/lib/python3.6/site-packages/psycopg2/.libs/libpq-bd31fe2b.so.5.11(+0x23969) [0x7f8a81d76969]
    /home/user/.local/lib/python3.6/site-packages/psycopg2/.libs/libpq-bd31fe2b.so.5.11(+0x24fc5) [0x7f8a81d77fc5]
    /home/user/.local/lib/python3.6/site-packages/psycopg2/.libs/libpq-bd31fe2b.so.5.11(PQconnectPoll+0xb78) [0x7f8a81d61ba8]
    /home/user/.local/lib/python3.6/site-packages/psycopg2/.libs/libpq-bd31fe2b.so.5.11(+0xfa28) [0x7f8a81d62a28]
    /home/user/.local/lib/python3.6/site-packages/psycopg2/.libs/libpq-bd31fe2b.so.5.11(PQconnectdb+0x1f) [0x7f8a81d6541f]
    /home/user/.local/lib/python3.6/site-packages/psycopg2/_psycopg.cpython-36m-x86_64-linux-gnu.so(+0x12b01) [0x7f8a81fb6b01]
    /home/user/.local/lib/python3.6/site-packages/psycopg2/_psycopg.cpython-36m-x86_64-linux-gnu.so(+0x1388f) [0x7f8a81fb788f]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x1fc402) [0x7f8abdbc4402]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyObject_FastCallDict+0x89) [0x7f8abdc2f169]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyObject_CallFunction_SizeT+0x124) [0x7f8abdc2fb84]
    /home/user/.local/lib/python3.6/site-packages/psycopg2/_psycopg.cpython-36m-x86_64-linux-gnu.so(+0xc258) [0x7f8a81fb0258]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(PyCFunction_Call+0x96) [0x7f8abdbdb976]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x76e0) [0x7f8abdb4cd80]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17bc6f) [0x7f8abdb43c6f]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17c35c) [0x7f8abdb4435c]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x4ec3) [0x7f8abdb4a563]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17bc6f) [0x7f8abdb43c6f]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(PyEval_EvalCodeEx+0x3e) [0x7f8abdb4472e]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(PyEval_EvalCode+0x1b) [0x7f8abdb454ab]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x1887bd) [0x7f8abdb507bd]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(PyCFunction_Call+0xc1) [0x7f8abdbdb9a1]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x76e0) [0x7f8abdb4cd80]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17bc6f) [0x7f8abdb43c6f]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17c35c) [0x7f8abdb4435c]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x4ec3) [0x7f8abdb4a563]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17aa63) [0x7f8abdb42a63]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17c51e) [0x7f8abdb4451e]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x4ec3) [0x7f8abdb4a563]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17aa63) [0x7f8abdb42a63]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17c51e) [0x7f8abdb4451e]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x4ec3) [0x7f8abdb4a563]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17aa63) [0x7f8abdb42a63]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17c51e) [0x7f8abdb4451e]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x4ec3) [0x7f8abdb4a563]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17aa63) [0x7f8abdb42a63]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyFunction_FastCallDict+0x2d5) [0x7f8abdb44085]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyObject_FastCallDict+0x131) [0x7f8abdc2f211]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyObject_CallMethodIdObjArgs+0xe6) [0x7f8abdc2f576]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(PyImport_ImportModuleLevelObject+0x45c) [0x7f8abda38b2c]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x77ca) [0x7f8abdb4ce6a]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17bc6f) [0x7f8abdb43c6f]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(PyEval_EvalCodeEx+0x3e) [0x7f8abdb4472e]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(PyEval_EvalCode+0x1b) [0x7f8abdb454ab]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x1887bd) [0x7f8abdb507bd]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(PyCFunction_Call+0xc1) [0x7f8abdbdb9a1]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x76e0) [0x7f8abdb4cd80]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17bc6f) [0x7f8abdb43c6f]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17c35c) [0x7f8abdb4435c]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x4ec3) [0x7f8abdb4a563]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17aa63) [0x7f8abdb42a63]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17c51e) [0x7f8abdb4451e]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x4ec3) [0x7f8abdb4a563]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17aa63) [0x7f8abdb42a63]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17c51e) [0x7f8abdb4451e]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(_PyEval_EvalFrameDefault+0x4ec3) [0x7f8abdb4a563]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17aa63) [0x7f8abdb42a63]
    /usr/lib/x86_64-linux-gnu/libpython3.6m.so.1.0(+0x17c51e) [0x7f8abdb4451e]
    <strong></em> end of backtrace *</strong></p>
  </blockquote>