Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flask crashes when static files are served (ProgrammingError: Recursive use of cursors not allowed) #36

Closed
nlohmann opened this issue May 19, 2016 · 8 comments · Fixed by #107

Comments

@nlohmann
Copy link

When I enable the flask-profiler, the app crashes when files from the static folder are served:

Traceback (most recent call last):
  File "flask\app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "flask\app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "flask\app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "flask\app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "flask\app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "flask\app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "flask\app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "flask\app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "flask_profiler\flask_profiler.py", line 91, in wrapper
    return wrapped(*args, **kwargs)
  File "flask_profiler\flask_profiler.py", line 72, in wrapper
    collection.insert(measurement.__json__())
  File "flask_profiler\storage\sqlite.py", line 128, in insert
    name))
ProgrammingError: Recursive use of cursors not allowed.
Traceback (most recent call last):
  File "flask\app.py", line 1836, in __call__
    return self.wsgi_app(environ, start_response)
  File "flask\app.py", line 1820, in wsgi_app
    response = self.make_response(self.handle_exception(e))
  File "flask\app.py", line 1403, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "flask\app.py", line 1817, in wsgi_app
    response = self.full_dispatch_request()
  File "flask\app.py", line 1477, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "flask\app.py", line 1381, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "flask\app.py", line 1475, in full_dispatch_request
    rv = self.dispatch_request()
  File "flask\app.py", line 1461, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "flask_profiler\flask_profiler.py", line 91, in wrapper
    return wrapped(*args, **kwargs)
  File "flask_profiler\flask_profiler.py", line 72, in wrapper
    collection.insert(measurement.__json__())
  File "flask_profiler\storage\sqlite.py", line 128, in insert
    name))
ProgrammingError: Recursive use of cursors not allowed.

I first though that this is, because requests to /static are not mentioned in the app routes, but also with a route with return app.send_static_file('index.html') I get the same error. All other routes (none are serving files from static) run fine.

I am using:

  • Python 2.7.5
  • Flask 0.10.1
  • Flask-Profiler 0.5

I am happy to provide more information if needed.

@ssharma94
Copy link

Hi nlohmann,
I am facing the same issue. Did you get to resolve the issue?

Thanks
Subhash

@nlohmann
Copy link
Author

nlohmann commented Jul 1, 2017

We could not resolve the issue and decided to stop using Flask Profiler.

@ssharma94
Copy link

Oh I am putting a fix and let you know if it works. However, did you get any other open source project to do the same.

@nlohmann
Copy link
Author

nlohmann commented Jul 3, 2017

No, we implemented some profiling ourselves. Nothing fancy, and a plugin like this would be appreciated.

@ragingra
Copy link

Was a solution for this problem found? I'm getting something very similar and cant figure it out.

Traceback (most recent call last):
    File "\lib\site-packages\flask\app.py", line 1997, in __call__
        return self.wsgi_app(environ, start_response)
    File "\lib\site-packages\flask\app.py", line 1985, in wsgi_app
        response = self.handle_exception(e)
    File "\lib\site-packages\flask\app.py", line 1540, in handle_exception
        reraise(exc_type, exc_value, tb)
    File "\lib\site-packages\flask\app.py", line 1982, in wsgi_app
        response = self.full_dispatch_request()
    File "\lib\site-packages\flask\app.py", line 1614, in full_dispatch_request
        rv = self.handle_user_exception(e)
    File "\lib\site-packages\flask\app.py", line 1517, in handle_user_exception
        reraise(exc_type, exc_value, tb)
    File "\lib\site-packages\flask\app.py", line 1612, in full_dispatch_request
        rv = self.dispatch_request()
    File "\lib\site-packages\flask\app.py", line 1598, in dispatch_request
        return self.view_functions[rule.endpoint](**req.view_args)
    File "\lib\site-packages\flask_httpauth.py", line 93, in decorated
        return f(*args, **kwargs)
    File "\lib\site-packages\flask_profiler\flask_profiler.py", line 212, in getRequestsTimeseries
        return jsonify({"series": collection.getTimeseries(args)})
    File "\lib\site-packages\flask_profiler\storage\sqlite.py", line 158, in getTimeseries
        self.cursor.execute(sql)
ProgrammingError: Recursive use of cursors not allowed.

@iurisilvio
Copy link
Contributor

iurisilvio commented Aug 18, 2018

The problem here is with a shared sqlite3 cursor.

self.cursor = self.connection.cursor()

https://stackoverflow.com/questions/26629080/python-and-sqlite3-programmingerror-recursive-use-of-cursors-not-allowed

If this is the reason, using another storage will fix the problem.

@AbdealiLoKo
Copy link

FWIW, I was using flask-profiler 1.7 all this while and didnt face an issue for a year. I just moved to 1.8.1 and am seeing it multiple times.

@dzpt
Copy link

dzpt commented Apr 28, 2024

same to me. error on 1.8.1, but works fine on 1.7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants