socialsentiment icon indicating copy to clipboard operation
socialsentiment copied to clipboard

sqlite3.ProgrammingError: Recursive use of cursors not allowed.

Open saikia1 opened this issue 7 years ago • 11 comments

While searching for new term this app throws the following error.

  File "/home/n3011/miniconda3/envs/twitter/lib/python3.6/site-packages/flask/app.py", line 2309, in __call__
    return self.wsgi_app(environ, start_response)
  File "/home/n3011/miniconda3/envs/twitter/lib/python3.6/site-packages/flask/app.py", line 2295, in wsgi_app
    response = self.handle_exception(e)
  File "/home/n3011/miniconda3/envs/twitter/lib/python3.6/site-packages/flask/app.py", line 1741, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "/home/n3011/miniconda3/envs/twitter/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/home/n3011/miniconda3/envs/twitter/lib/python3.6/site-packages/flask/app.py", line 2292, in wsgi_app
    response = self.full_dispatch_request()
  File "/home/n3011/miniconda3/envs/twitter/lib/python3.6/site-packages/flask/app.py", line 1815, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/home/n3011/miniconda3/envs/twitter/lib/python3.6/site-packages/flask/app.py", line 1718, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "/home/n3011/miniconda3/envs/twitter/lib/python3.6/site-packages/flask/_compat.py", line 35, in reraise
    raise value
  File "/home/n3011/miniconda3/envs/twitter/lib/python3.6/site-packages/flask/app.py", line 1813, in full_dispatch_request
    rv = self.dispatch_request()
  File "/home/n3011/miniconda3/envs/twitter/lib/python3.6/site-packages/flask/app.py", line 1799, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "/home/n3011/miniconda3/envs/twitter/lib/python3.6/site-packages/dash/dash.py", line 967, in dispatch
    return self.callback_map[target_id]['callback'](*args)
  File "/home/n3011/miniconda3/envs/twitter/lib/python3.6/site-packages/dash/dash.py", line 907, in add_context
    output_value = func(*args, **kwargs)
  File "/home/n3011/work/twitter/socialsentiment/dash_mess.py", line 228, in update_pie_chart
    sentiment_pie_dict = cache.get('sentiment_shares', sentiment_term)
  File "/home/n3011/work/twitter/socialsentiment/cache.py", line 41, in get
    result = self.cursor.execute("SELECT value FROM {} WHERE key = ?".format(pool), (key,)).fetchone()
sqlite3.ProgrammingError: Recursive use of cursors not allowed.

saikia1 avatar Jan 12 '19 07:01 saikia1

After spending hours, i managed to solve the same issue. You have to make the following appends to the cache.py file: 1. Add the

`import time import os from threading import Lock

#Define the lock globally to avoid the "recursive use of cursors not allowed" error lock= Lock()`

at the top

  1. Add the following line before every self.cursor operation

#lock the cursor lock.acquire(True)

  1. Add the following line after every cursor operation in the same .py file.

     #release the cursor
     lock.release()
    

Sailor74 avatar Mar 03 '19 20:03 Sailor74

` #lock the cursor lock.acquire(True)

    # get data from cache
    result = self.cursor.execute("SELECT value FROM {} WHERE key = ?".format(pool), (key,)).fetchone()

    #release the cursor
    lock.release()`

but still getting the same error socialsentiment/cache.py", line 48, in get result = self.cursor.execute("SELECT value FROM {} WHERE key = ?".format(pool), (key,)).fetchone() sqlite3.ProgrammingError: Recursive use of cursors not allowed.

udipta avatar Apr 06 '19 17:04 udipta

cache.txt I have uploaded the python code (in txt format) so that you can maybe re-apply.

Sailor74 avatar Apr 07 '19 00:04 Sailor74

@Sailor74 i tried with your code but it still giving the same error Screenshot from 2019-04-10 02-23-33

please help me to find out the exact issue.

udipta avatar Apr 09 '19 20:04 udipta

ok interesting.. it could be one of the below solutions. Pls give them a try at your own risk.

your requirements should include the following libraries. Check if you are missing any. dash dash-core-components dash-html-components dash-renderer dash-table tweepy vaderSentiment unidecode plotly pandas regex python-memcached h5py numpy Werkzeug textblob

Secondly if you have anaconda, it maybe causing some conflicts:

  1. Make sure you have Python3.6+. My best idea here is to get rid of Anaconda and venvs and do it the regular way
  2. Maybe try to remove sql database file and start it again?
  3. uninstall the dash files and install the older version.

python -m pip install --upgrade pysqlite3

Also venv...Activate that venv Run Python

good luck...

Thank you,

Özgür

On Tue, Apr 9, 2019 at 4:58 PM udipta [email protected] wrote:

@Sailor74 https://github.com/Sailor74 i tried with your code but it still giving the same error [image: Screenshot from 2019-04-10 02-23-33] https://user-images.githubusercontent.com/28093579/55834794-4d054d00-5b38-11e9-8df5-2dc5d063c2d6.png

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/Sentdex/socialsentiment/issues/12#issuecomment-481433190, or mute the thread https://github.com/notifications/unsubscribe-auth/AI1SJ2C1WACEJJvzAP07MXgQ4HQ85psbks5vfP8EgaJpZM4Z8icI .

Sailor74 avatar Apr 10 '19 01:04 Sailor74

@Sailor74 did you try to run the code before in your system? because I am again and again getting the same error and I am not able to figure it out.

udipta avatar Apr 10 '19 14:04 udipta

Of course... it is live at social.ozgurgenc.dev

Özgür Genç Sent from my iPhone +1 646 946 2389 Please disregard spelling errors.


From: udipta [email protected] Sent: Wednesday, April 10, 2019 10:46 AM To: Sentdex/socialsentiment Cc: Ozgur Genc; Mention Subject: Re: [Sentdex/socialsentiment] sqlite3.ProgrammingError: Recursive use of cursors not allowed. (#12)

@Sailor74https://github.com/Sailor74 did you try to run the code before in your system? because I am again and again getting the same error and I am not able to figure it out.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/Sentdex/socialsentiment/issues/12#issuecomment-481721772, or mute the threadhttps://github.com/notifications/unsubscribe-auth/AI1SJ8J1GARnoXLlVEkajUaG9ag4vaCLks5vfflRgaJpZM4Z8icI.

Sailor74 avatar Apr 10 '19 16:04 Sailor74

@Sentdex @Sailor74 How to resolve the error. socialsentiment/cache.py", line 48, in get result = self.cursor.execute("SELECT value FROM {} WHERE key = ?".format(pool), (key,)).fetchone() sqlite3.ProgrammingError: Recursive use of cursors not allowed.

I have tried every solution but unable to resolve.

udipta avatar Apr 19 '19 18:04 udipta

I have it fully working in conda environment after receiving this error...remove any *.db files and py cache folder in your sentiment directory. Run twitter_stream.py, leave it open and in another terminal run the dev_server. This is using cache.py from repo non modified. however I did use these pip install ... dash==0.30.0 dash-core-components==0.38.0 dash-html-components==0.13.2 dash-renderer==0.15.0

chris-ault avatar Jun 05 '19 06:06 chris-ault

Adding the locks solved the error for me, but made the GUI very slow. @Sailor74 i think you posted the incorrect cache.py file, it has no locks. Can you please check?

Mesmer88 avatar Jul 03 '19 13:07 Mesmer88

Follow

  1. @chris-ault Steps
  2. Steps to incorporate locks in every cursor operation as mentioned by @Sailor74
  3. Run dev_server.py

it works, and i see no lag in the response as far as speed is concerned.

masmedh avatar Oct 18 '20 18:10 masmedh