Visual Code debug requirement GEVENT_SUPPORT=True

6,111 views
Skip to first unread message

Jacinto Parga

unread,
Oct 15, 2020, 5:37:04 PM10/15/20
to py4web
Hi,
I’m trying to configure Visual Code to debug Py4web. I was asked to create a global variable GEVENT_SUPPORT=True.
Is gevent a mandatory requirement yet?
If it is, where do I have to place the global variable. I tried in common.py and in settings.py with no success.


Jim Steil

unread,
Oct 15, 2020, 5:46:56 PM10/15/20
to py4web
I wish I had an answer for you.  I cannot debug through pycharm either.

Traceback (most recent call last):
 
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
 
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
 
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
 
File "<frozen importlib._bootstrap_external>", line 783, in exec_module
 
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
 
File "/home/jim/dev/jpsteil/py4web/py4web/__init__.py", line 1, in <module>
   
from .core import (
 
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
 
File "<frozen importlib._bootstrap>", line 152, in __exit__
 
File "<frozen importlib._bootstrap>", line 107, in release
RuntimeError: cannot release un-acquired lock
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
 
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
 
File "<frozen importlib._bootstrap>", line 961, in _find_and_load_unlocked
 
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
 
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
 
File "<frozen importlib._bootstrap>", line 152, in __exit__
 
File "<frozen importlib._bootstrap>", line 107, in release
RuntimeError: cannot release un-acquired lock
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
 
File "<frozen importlib._bootstrap>", line 107, in release
RuntimeError: cannot release un-acquired lock
python
-BaseException

-Jim

Andrew Gavgavian

unread,
Oct 15, 2020, 5:52:32 PM10/15/20
to py4web
I use VSCode for all of my py4web development. I've had the same issue if I just hit F5 to run the program, but CTRL+F5 runs without debugging and allows the program to run just fine. Here is my launch.json based off the built in Django one as well:

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python: Py4web",
            "type": "python",
            "request": "launch",
            "program": "${workspaceFolder}/py4web.py",
            "args": [
                "run",
                "apps"
            ],
        }
    ]
}

~Andrew

P.S. Jim how do you get the nice code formatting in groups? No matter what I try I can't make it look right.

Jim Steil

unread,
Oct 15, 2020, 6:03:33 PM10/15/20
to py4web
I'm not using the new google groups yet, they took the code formatter out.  In the old google groups, highlight a section of code and then click on the 

{}

in the editor toolbar to format.  I'm hopeful that feature will appear in the new google groups before they kill the old version.

-Jim

Andrew Gavgavian

unread,
Oct 15, 2020, 6:05:55 PM10/15/20
to py4web
Wow that's amazing, thanks for the info that will help in the future. Yeah I hope it will be added to the new version as well, it's stupid this older version has so many more formatting features than the new one!

~Andrew

Jacinto Parga

unread,
Oct 16, 2020, 4:01:53 AM10/16/20
to py4web
Thanks for the answers.

I finally got it, this is my launch.json:


Introducir código aquí...{
// Use IntelliSense para saber los atributos posibles.
// Mantenga el puntero para ver las descripciones de los existentes atributos.
// Para más información, visite: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Py4web",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/main.py",
"console": "integratedTerminal",
"gevent": true
}
]
}


The missunderstanding  was that I tried to create a global variable GEVENT_SUPPORT=True in the code of the application instead of the Visual Code debug environment. So "gevent": true, in the launch.json fixed it.

I use the pip installed py4web, so I use a main.py file to launch the single application I want to debug, bu it also works for the py4web.py run apps .

I will make a video, if I can, this weekend.




Jacinto Parga

unread,
Oct 16, 2020, 4:09:29 AM10/16/20
to py4web
Yes, the same exception raised for me: 

Traceback (most recent call last):
  File "/home/jacinto/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 193, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "/home/jacinto/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/jacinto/.vscode/extensions/ms-python.python-2020.9.114305/pythonFiles/lib/python/debugpy/__main__.py", line 45, in <module>
    cli.main()
  File "/home/jacinto/.vscode/extensions/ms-python.python-2020.9.114305/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 430, in main
    run()
  File "/home/jacinto/.vscode/extensions/ms-python.python-2020.9.114305/pythonFiles/lib/python/debugpy/../debugpy/server/cli.py", line 267, in run_file
    runpy.run_path(options.target, run_name=compat.force_str("__main__"))
  File "/home/jacinto/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 263, in run_path
    return _run_module_code(code, init_globals, run_name,
  File "/home/jacinto/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 96, in _run_module_code
    _run_code(code, mod_globals, init_globals,
  File "/home/jacinto/.pyenv/versions/3.8.2/lib/python3.8/runpy.py", line 86, in _run_code
    exec(code, run_globals)
  File "/home/jacinto/proyectos/py3/py4web/operativo/canaldenunciasweb/main.py", line 8, in <module>
    from py4web.core import (
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 152, in __exit__
  File "<frozen importlib._bootstrap>", line 107, in release
RuntimeError: cannot release un-acquired lock
It seems that the gevent monkey-patching is being used.
Please set an environment variable with:
GEVENT_SUPPORT=True
to enable gevent support in the debugger.

In visual code I fixed with "gevent":true in launch.json.

Nico Zanferrari

unread,
Oct 16, 2020, 6:45:36 AM10/16/20
to py4web
Hi,

you can also add :

          "args": ["run", "apps"],

to  launch.json in order to debug py4web.py directly ;-)

Nico 



--
You received this message because you are subscribed to the Google Groups "py4web" group.
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/py4web/73572457-fdd7-4267-93a6-a01a606e66f6o%40googlegroups.com.

Jim Steil

unread,
Oct 16, 2020, 9:21:06 AM10/16/20
to py4web
Thanks for the nudge.  Knowing it was a Gevent issue for VS Code I did some digging on PyCharm forums and found there is a setting to fix this issue.

In PyCharm, enable Settings | Build, Execution, Deployment | Python Debugger | Gevent compatible

Debugger is now working for me in PyCharm.

-Jim
To unsubscribe from this group and stop receiving emails from it, send an email to py4web+unsubscribe@googlegroups.com.

Andrew Rogers

unread,
Nov 6, 2020, 8:48:28 PM11/6/20
to py4web
Hi jpa...

Would you mind posting your main.py file for me please? And did you ever get a video made up?

Thanks
Andrew

Jacinto Parga

unread,
Nov 7, 2020, 9:18:04 AM11/7/20
to py4web
Hi,

yes is the main.py that is in deployment_tools/gae because the app I show was being deployed in GAE. I made a few additions to run and deploy it in localhost. This is the main py from the example: 

import os
import site

""" This is the main.py file according to deployments/tools with some addings to allow local testing.
Can be used in local debugging replacing py4web.py
"""
site.addsitedir(os.path.join(os.path.dirname(__file__), "lib"))

# This is for finding the path of py4web in GAE

from py4web.core import (
Reloader,
bottle,
)

os.environ["PY4WEB_DASHBOARD_MODE"] = "full" # or 'demo' or 'none'
os.environ["PY4WEB_SERVICE_DB_URI"] = "sqlite:memory" # "google:datastore" #
os.environ["PY4WEB_APPS_FOLDER"] = os.path.join(os.path.dirname(__file__), "apps")
os.environ["PY4WEB_SERVICE_FOLDER"] = os.path.join(
os.path.dirname(__file__), "apps/.service"
)

# For deploying in GAE
if os.getenv("GAE_ENV", "").startswith("standard"):

# Production in the standard environment
Reloader.import_apps()
app = bottle.default_app()

# For local testing
else:
# Local execution.

if __name__ == "__main__":
# This is used when running locally only. When deploying to Google App
# Engine, a webserver process such as Gunicorn will serve the app. This
# can be configured by adding an `entrypoint` to app.yaml.
# App Engine itself will serve those files as configured in app.yaml.

# app.run(host="127.0.0.1", port=9000, debug=True) Also works but does not allow _dashboard

os.system("py4web run apps -P 9000")




Actually I am playing now with main.py in this way:

...
try:
    
if __name__ == "__main__":
# This is used when running locally only. When deploying to Google App
# Engine, a webserver process such as Gunicorn will serve the app. This
# can be configured by adding an `entrypoint` to app.yaml.
# App Engine itself will serve those files as configured in app.yaml.

# app.run(host="127.0.0.1", port=9000, debug=True) Also works but does not allow _dashboard

os.system("py4web run apps -P 9000")
except:
# Production in the standard environment
Reloader.import_apps()
app = bottle.default_app()
pass
Reply all
Reply to author
Forward
0 new messages