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

Python Kernel dies when using ibm_db.connect #9347

Closed
parodayco opened this issue Mar 11, 2022 · 32 comments
Closed

Python Kernel dies when using ibm_db.connect #9347

parodayco opened this issue Mar 11, 2022 · 32 comments
Assignees
Labels
info-needed Issue requires more information from poster

Comments

@parodayco
Copy link

parodayco commented Mar 11, 2022

Issue Type: Bug

My python kernel dies when I run ibm_db.connect() or ibm_db_dbi.connect() in VS Code Jupyter notebook cells. Here is the console output:

Error 08:48:19: Disposing session as kernel process died ExitCode: undefined, Reason: /usr/local/lib/python3.9/site-packages/traitlets/traitlets.py:2202: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use 'hmac-sha256' instead of '"hmac-sha256"' if you require traitlets >=5.
  warn(
/usr/local/lib/python3.9/site-packages/traitlets/traitlets.py:2157: FutureWarning: Supporting extra quotes around Bytes is deprecated in traitlets 5.0. Use 'b13bc39e-6f5f-4a5e-b875-93a86653eb31' instead of 'b"b13bc39e-6f5f-4a5e-b875-93a86653eb31"'.
  warn(

Info 08:48:19: Dispose Kernel process
Error 08:48:19: Raw kernel process exited code: undefined

I cannot reproduce the issue outside of the VS Code Jupyter renderer; the same function runs fine as a python script in VS Code and in a local Jupyterlab environment. In all cases, I'm using the same python environment and packages.

MacOS 12.2.1
Python 3.9.10
python3 -m pip install ipykernel jupyterlab pandas ibm-db

Extension version: 2022.2.1924087327
VS Code version: Code 1.65.2 (c722ca6c7eed3d7987c0d5c3df5c45f6b15e77d1, 2022-03-10T14:33:49.188Z)
OS version: Darwin x64 21.3.0
Restricted Mode: No

System Info
Item Value
CPUs Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz (16 x 2400)
GPU Status 2d_canvas: enabled
gpu_compositing: enabled
metal: disabled_off
multiple_raster_threads: enabled_on
oop_rasterization: enabled
opengl: enabled_on
rasterization: enabled
skia_renderer: disabled_off_ok
video_decode: enabled
webgl: enabled
webgl2: enabled
Load (avg) 2, 2, 2
Memory (System) 32.00GB (3.73GB free)
Process Argv --crash-reporter-id 91bde56a-ddbf-4e4b-9ab2-5db38b83b07e
Screen Reader no
VM 0%
Extensions (11)
Extension Author (truncated) Version
gather ms- 2022.3.0
python ms- 2022.2.1924087327
vscode-pylance ms- 2022.3.1
jupyter ms- 2022.2.1030672458
jupyter-renderers ms- 1.0.6
remote-containers ms- 0.224.2
remote-ssh ms- 0.76.1
remote-ssh-edit ms- 0.76.1
autodocstring njp 0.6.1
vscode-data-preview Ran 2.3.0
vscodeintellicode Vis 1.2.17
A/B Experiments
vsliv368cf:30146710
vsreu685:30147344
python383:30185418
vspor879:30202332
vspor708:30202333
vspor363:30204092
vswsl492cf:30256860
vstes627:30244334
pythonvspyl392:30443607
pythontb:30283811
pythonptprofiler:30281270
vshan820:30294714
vstes263:30335439
vscorecescf:30445987
pythondataviewer:30285071
vscod805cf:30301675
pythonvspyt200:30340761
binariesv615:30325510
bridge0708:30335490
bridge0723:30353136
vsaa593:30376534
vsc1dst:30438360
pythonvs932:30410667
wslgetstarted:30449410
vsclayoutctrt:30451275
dsvsc008:30440022
pythonvsnew555:30450902
vscscmwlcmt:30438805
vscgsvidc:30447482
cppdebugcf:30451567
pynewfile477cf:30450039

@karthiknadig karthiknadig transferred this issue from microsoft/vscode-python Mar 13, 2022
@MeganBeckett
Copy link

I'm also having these issues with VScode and running Jupyter notebooks - it happens with several cells, at different points in the notebook, so for me, it's not linked to running a specific function.

The error message is exactly the same as above.

Package              Version
-------------------- ------------
aiobotocore          2.1.2
aiohttp              3.8.1
aioitertools         0.10.0
aiosignal            1.2.0
argon2-cffi          21.3.0
argon2-cffi-bindings 21.2.0
asttokens            2.0.5
async-timeout        4.0.2
attrs                21.4.0
backcall             0.2.0
bleach               4.1.0
botocore             1.23.24
branca               0.4.2
certifi              2021.10.8
cffi                 1.15.0
charset-normalizer   2.0.12
cycler               0.11.0
debugpy              1.5.1
decorator            5.1.1
defusedxml           0.7.1
descartes            1.1.0
entrypoints          0.4
executing            0.8.3
folium               0.12.1.post1
fonttools            4.30.0
frozenlist           1.3.0
fsspec               2022.2.0
idna                 3.3
ipykernel            6.9.1
ipython              8.1.1
ipython-genutils     0.2.0
ipywidgets           7.6.5
jedi                 0.18.1
Jinja2               3.0.3
jmespath             0.10.0
jsonschema           4.4.0
jupyter              1.0.0
jupyter-client       7.1.2
jupyter-console      6.4.3
jupyter-core         4.9.2
jupyterlab-pygments  0.1.2
jupyterlab-widgets   1.0.2
kiwisolver           1.3.2
MarkupSafe           2.1.0
matplotlib           3.5.1
matplotlib-inline    0.1.3
mistune              0.8.4
mizani               0.7.3
multidict            6.0.2
nbclient             0.5.13
nbconvert            6.4.2
nbformat             5.2.0
nest-asyncio         1.5.4
notebook             6.4.8
numpy                1.22.3
packaging            21.3
palettable           3.3.0
pandas               1.4.1
pandocfilters        1.5.0
parso                0.8.3
pathlib              1.0.1
patsy                0.5.2
pexpect              4.8.0
pickleshare          0.7.5
Pillow               9.0.1
pip                  22.0.3
plotnine             0.8.0
prometheus-client    0.13.1
prompt-toolkit       3.0.28
ptyprocess           0.7.0
pure-eval            0.2.2
pycparser            2.21
Pygments             2.11.2
pyparsing            3.0.7
pyrsistent           0.18.1
python-dateutil      2.8.2
pytz                 2021.3
pyzmq                22.3.0
qtconsole            5.2.2
QtPy                 2.0.1
requests             2.27.1
s3fs                 2022.2.0
scipy                1.8.0
Send2Trash           1.8.0
setuptools           60.9.3
six                  1.16.0
stack-data           0.2.0
statsmodels          0.13.2
terminado            0.13.3
testpath             0.6.0
tornado              6.1
traitlets            5.1.1
typing_extensions    4.1.1
urllib3              1.26.8
wcwidth              0.2.5
webencodings         0.5.1
wheel                0.37.1
widgetsnbextension   3.5.2
wrapt                1.14.0
yarl                 1.7.2

@parodayco
Copy link
Author

parodayco commented Mar 14, 2022

Thanks, @MeganBeckett. Can you confirm that your code cells will run as separate python scripts in VS Code without triggering a kernel panic? Also in ipython and/or jupyter environment (Jupyterlab etc) outside VS Code? There is some extra process in VS Code Jupyter that does not occur elsewhere.

@DonJayamanne
Copy link
Contributor

@parodayco @MeganBeckett
Please could you provide the output from the Jupyter output panel

@DonJayamanne DonJayamanne added info-needed Issue requires more information from poster kernel-crash and removed needs-triage labels Mar 14, 2022
@parodayco
Copy link
Author

@DonJayamanne I pasted that in my initial post, the error message is from the Jupyter output panel

@DonJayamanne
Copy link
Contributor

DonJayamanne commented Mar 14, 2022

@parodayco Please could you paste all of the output, i'd like to see the initial logs with information about the interpreter and paths, and the like.

Please could you also provide the following info:

  • Run the following in the terminal and provide the output for that
    which python3
  • Sample code that fails in VS Code and works successfully in Jupyter
  • Please confirm the kernel dies at the exact moment when you run the following code. Possible some environment variables or the like are different and causing this block of code to fail.
    ibm_db.connect() or ibm_db_dbi.connect()
  • Please run the following in vs code and jupyter and compare the values for the env and path variable.
    I suspect some env variable or path variable isn't correct and causing the package to take the process down.
    Would help if you could identify the different (or perhaps share the values from both & I could look for the differences)
import os
print(os.environ)

import sys
print(sys.path)

@kfchou

This comment was marked as off-topic.

@parodayco
Copy link
Author

parodayco commented Mar 15, 2022

@DonJayamanne
which python3
/usr/local/bin/python3

python3 -m venv test && . test/bin/activate && python3 -m pip install ipykernel ibm-db

Cell 1

import ibm_db, ibm_db_dbi as dbi
import json

Cell 2

with open('connection.json', 'r') as config:
    dsn_config = json.loads(config.read())

Cell 3

conn = dbi.connect(
    (
        'database={};'
        'hostname={};'
        'port={};'
        'apikey={};'
        'authentication=gssplugin;'
        'protocol=tcpip;'
        'security=ssl;'
    ).format(
        dsn_config.get('database'),
        dsn_config.get('host'),
        dsn_config.get('port'),
        dsn_config.get('api_key')
    ))

Output

Info 15:21:42: Execute Cells request 1
Info 15:21:42: Execute Cell 1 ~/Projects/WF360/test.ipynb
Info 15:21:42: Cell 1 executed with state Success
Info 15:21:44: Execute Cells request 2
Info 15:21:44: Execute Cell 2 ~/Projects/WF360/test.ipynb
Info 15:21:44: Cell 2 executed with state Success
Info 15:21:48: Execute Cells request 3
Info 15:21:48: Execute Cell 3 ~/Projects/WF360/test.ipynb
Error 15:21:49: Disposing session as kernel process died ExitCode: undefined, Reason: /usr/local/lib/python3.9/site-packages/traitlets/traitlets.py:2202: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use 'hmac-sha256' instead of '"hmac-sha256"' if you require traitlets >=5.
  warn(
/usr/local/lib/python3.9/site-packages/traitlets/traitlets.py:2157: FutureWarning: Supporting extra quotes around Bytes is deprecated in traitlets 5.0. Use '56de8934-1fb4-4163-b524-3379368e7586' instead of 'b"56de8934-1fb4-4163-b524-3379368e7586"'.
  warn(

Info 15:21:49: Dispose Kernel process
Error 15:21:49: Raw kernel process exited code: undefined
Info 15:21:49: Cancel all remaining cells due to dead kernel
Info 15:21:49: Cancel pending cells
Info 15:21:49: Cell 3 executed with state Success

not calling any environmental variables
same outcome whether I run ibm_db.connect() or ibm_db_dbi.connect()
os.environ and sys.path are identical in VS Code Jupyter and Jupyterlab 3.3.2

All above code consolidated and run in a test.py works fine in VS Code. It only fails when run in a test.ipynb

@DonJayamanne
Copy link
Contributor

All above code consolidated and run in a test.py works fine in VS Code. It only fails when run in a test.ipynb

How are you running test.py in vscode? in a terminal or debugging

@parodayco
Copy link
Author

parodayco commented Mar 16, 2022

It runs successfully in the terminal but shows this when debugging

source /Users/philipparodayco/.venv/test/bin/activate
philipparodayco@Philips-MacBook-Pro Projects % source /Users/philipparodayco/.venv/test/bin/activate
(test) philipparodayco@Philips-MacBook-Pro Projects %  /usr/bin/env /Users/philipparodayco/.venv/test/bin/python /Users/philipparodayco/.vsco
de/extensions/ms-python.python-2022.2.1924087327/pythonFiles/lib/python/debugpy/launcher 50806 -- /Users/philipparodayco/Projects/WF360/test.
py 
Python(11584,0x10f539600) malloc: *** error for object 0x7ffb55467670: pointer being freed was not allocated
Python(11584,0x10f539600) malloc: *** set a breakpoint in malloc_error_break to debug
(test) philipparodayco@Philips-MacBook-Pro Projects % 

@DonJayamanne DonJayamanne changed the title python kernel process dies because of deprecated support for extra string quotes in traitlets Python Kernel dies when using ibm_db.connect Mar 16, 2022
@DonJayamanne
Copy link
Contributor

It runs successfully in the terminal but shows this when debugging

Thanks for that information, however lets not introduce too many other variables for now.

@parodayco Does Jupyter work when you install a previous version like 2021.11.xxx
Please could you try installing that version and letting me know if it works for you.

@parodayco
Copy link
Author

@DonJayamanne I tried multiple versions of the Jupyter extension back to 2021.09.11xxx but the kernel process dies with variations of the same error message. For example

Warn 2022-03-17 08:45:25: Kernel 17757 as possibly died, StdErr from Kernel Process /Users/philipparodayco/.venv/vscode/lib/python3.9/site-packages/traitlets/traitlets.py:2202: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use 'hmac-sha256' instead of '"hmac-sha256"' if you require traitlets >=5.

and

{"jsonrpc": "2.0", "method": "kernel_died", "params": {"exit_code": -6, "reason": ""}}
Error 2022-03-17 08:45:38: Kernel died [s [Error]: Kernel died (code: -6). warn(,
/Users/philipparodayco/.venv/vscode/lib/python3.9/site-packages/traitlets/traitlets.py:2202: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use 'hmac-sha256' instead of '"hmac-sha256"' if you require traitlets >=5.

@GoMapur
Copy link

GoMapur commented Mar 17, 2022

Hi I'm experiencing the exact same issue, wonder if there's any workaround for now

@parodayco
Copy link
Author

@DonJayamanne I saw you renamed this ticket and I'd like to be clear that ibm_db.connect does not call the traitlets module. That is an ipykernel dependency which is required by the VSCode Jupyter extension. The kernel failure does not occur when I run ibm_db.connect elsewhere.

@DonJayamanne
Copy link
Contributor

DonJayamanne commented Mar 17, 2022

Hi I'm experiencing the exact same issue, wonder if there's any workaround for now

Please could you provide the following information:

  • Version of extension
  • Version of Python
  • Output from the Jupyter output panel
  • The code that causes the failure.

w you renamed this ticket and I'd like to be clear that ibm_db.connect does not call the traitlets module

The traitlets module issue is not an error, its just a warning displayed by Jupyter, even Jupyter uses IPyKernel and you'd see this exact same error in jupyter as well (if you enable the logging).
Renamed to include ibm_db.connect as you have conrirmed that the kernel crashes when it hits that block of code, and not anything else.

I understand the error message indicates that it could be the cause, but thats a best guess from our end looking at the output in stderr stream.

@parodayco
Copy link
Author

The traitlets module issue is not an error, its just a warning displayed by Jupyter, even Jupyter uses IPyKernel and you'd see this exact same error in jupyter as well (if you enable the logging).

That's the thing, Don. When I enable the Log Console in Jupyterlab and set the proper levels, it shows no warning message about traitlets and no errors running ibm_db.connect. The kernel does not crash and I am able to execute queries.

@DonJayamanne
Copy link
Contributor

@parodayco
Please could you try this in our latest Jupyter extesnion and let me know how this goes.

python3 -m pip install ipykernel jupyterlab pandas ibm-db
python3 -m venv test && . test/bin/activate && python3 -m pip install ipykernel ibm-db

Looking at the information you provided, when you run Jupyter outside vs code i think you are using python3 to run jupyter.
However in vscode you are using the environment test.

Please try the following:

  • Start Jupyte outside VS Code and print the following in vscode & let me know what you get:
     	import sys
     	print(sys.executable)
     	import ibm_db
     	print(ibm_db.__file__)
  • Run the same code in VS Code and let me know what you get:
     	import sys
     	print(sys.executable)
     	import ibm_db
     	print(ibm_db.__file__)

@parodayco
Copy link
Author

@DonJayamanne I followed your instructions except I created two virtual environments.

python3 -m venv .venv/lab && . .venv/lab/bin/activate && python3 -m pip install ipykernel jupyterlab pandas ibm-db
python3 -m venv .venv/test && . .venv/test/bin/activate && python3 -m pip install ipykernel ibm-db

Here are the outputs you requested:

  • Jupyterlab (lab env)
print(sys.executable)
/Users/philipparodayco/.venv/lab/bin/python3
print(ibm_db.__file__)
/Users/philipparodayco/.venv/lab/lib/python3.9/site-packages/ibm_db.cpython-39-darwin.so
  • VS Code (test env)
print(sys.executable)
/Users/philipparodayco/.venv/test/bin/python
print(ibm_db.__file__)
/Users/philipparodayco/.venv/test/lib/python3.9/site-packages/ibm_db.cpython-39-darwin.so

Both environments are running python 3.9.12

The ibm_db connection works in Jupyterlab but dies in VS Code using the current Jupyter extension. Here is the full output.

Error 12:28:10: Disposing session as kernel process died ExitCode: undefined, Reason: /Users/philipparodayco/.venv/test/lib/python3.9/site-packages/traitlets/traitlets.py:2202: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use 'hmac-sha256' instead of '"hmac-sha256"' if you require traitlets >=5.
  warn(
/Users/philipparodayco/.venv/test/lib/python3.9/site-packages/traitlets/traitlets.py:2157: FutureWarning: Supporting extra quotes around Bytes is deprecated in traitlets 5.0. Use '1c7d2f68-fe32-4ac5-af93-5cf3e0ca4d65' instead of 'b"1c7d2f68-fe32-4ac5-af93-5cf3e0ca4d65"'.
  warn(

Info 12:28:10: Dispose Kernel process
Error 12:28:10: Raw kernel process exited code: undefined
Warn 12:28:10: Error in waiting for cell to complete [Error: Canceled future for execute_request message before replies were done
	at t.KernelShellFutureHandler.dispose (/Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:1204175)
	at /Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:1223227
	at Map.forEach (<anonymous>)
	at v._clearKernelState (/Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:1223212)
	at v.dispose (/Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:1216694)
	at /Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:533674
	at t.swallowExceptions (/Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:913059)
	at dispose (/Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:533652)
	at t.RawSession.dispose (/Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:537330)
	at runMicrotasks (<anonymous>)
	at processTicksAndRejections (node:internal/process/task_queues:96:5)]
Warn 12:28:10: Cell completed with errors [Error: Canceled future for execute_request message before replies were done
	at t.KernelShellFutureHandler.dispose (/Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:1204175)
	at /Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:1223227
	at Map.forEach (<anonymous>)
	at v._clearKernelState (/Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:1223212)
	at v.dispose (/Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:1216694)
	at /Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:533674
	at t.swallowExceptions (/Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:913059)
	at dispose (/Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:533652)
	at t.RawSession.dispose (/Users/philipparodayco/.vscode/extensions/ms-toolsai.jupyter-2022.3.1000901801/out/extension.js:2:537330)
	at runMicrotasks (<anonymous>)
	at processTicksAndRejections (node:internal/process/task_queues:96:5)]
Info 12:28:10: Cancel all remaining cells true || Error || undefined
Info 12:28:10: Cancel pending cells
Info 12:28:10: Cell 6 executed with state Error

@DonJayamanne
Copy link
Contributor

DonJayamanne commented Apr 11, 2022

@parodayco Thanks for the information and your patience. I'm still at a loss as to why this is happening.
Please could you print sys.path from Jupyter Lab & VS Code and upload those here.
Also, please could you add the following setting into your user settings.json file, reload VS Code and run the cells again & send the output, thanks (hopefully there will be more information from the kernel as to why the process died).

"jupyter.enablePythonKernelLogging": true

Also, how are you running Jupyter Lab form the terminal.
I'm assuming you have install Jupyter lab into the new venv named 'lab` and then launching Jupyter lab from within that.
If so, please could you try the following:

python3 -m venv test && . test/bin/activate && python -m pip install ipykernel ibm-db && export PYTHONNOUSERSITE=True && python -m jupyter lab

Basically setup the env variable PYTHONNOUSERSITE=True just before launching Jupyter lab & then try to see whether you can run the same code in Jupyter lab. I suspect it will fail there too once this env variable has been setup.

@parodayco
Copy link
Author

@DonJayamanne no worries, I'm happy to help solve this. The sys.path was basically the same:

['/Users/philipparodayco/Projects/WF360',
 '/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python39.zip',
 '/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9',
 '/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload',
 '',
 '/Users/philipparodayco/.venv/lab/lib/python3.9/site-packages']
['/Users/philipparodayco/Projects/WF360',
 '/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python39.zip',
 '/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9',
 '/usr/local/Cellar/python@3.9/3.9.12/Frameworks/Python.framework/Versions/3.9/lib/python3.9/lib-dynload',
 '',
 '/Users/philipparodayco/.venv/test/lib/python3.9/site-packages',
 '/Users/philipparodayco/Library/Python/3.9/lib/python/site-packages']

p.s. I have no python packages installed in my Library.

You were correct about how I ran Jupyterlab. I added the env variable you requested and restarted lab. The ibm-db connection still worked fine and I validated !echo $PYTHONNOUSERSITE printed True in the notebook and didn't crash the kernel.

For VS Code, I enabled the logging you requested and attached the full output with the kernel crash.
vscode_test_output.txt

@DonJayamanne
Copy link
Contributor

@parodayco

'/Users/philipparodayco/Library/Python/3.9/lib/python/site-packages']

Looking at the paths, there seems to be a slight difference in the paths. Please could you let me know which one (Jupyter or VS Code) outputs the value '/Users/philipparodayco/Library/Python/3.9/lib/python/site-packages'] in sys.path.
Also, please could you try printing the paths again from Jupyter with the env variable PYTHONNOUSERSITE set.

Please could you update to the latest pre-release version of the Jupyter extension & send the logs once again.

Possible some environment variables or the like are different and causing this block of code to fail.

Also, please could you print the env variables from Jupyter as well as VS Code so I could compare them (optionally you could compare them your self if you believe there's sensitive information in any of the env variables).
print(os.environ)

@parodayco
Copy link
Author

@DonJayamanne that Library path was empty, an artifact of installing poetry. I uninstalled poetry and removed the entire Library/Python folder. It no longer shows up in sys.path on VSCode, so it's now identical to Jupyterlab.

I installed the latest pre-release Jupyter extension v2022.4.1000912146 but the kernel still crashes on ibm_db.connect(). vscode_test_output.txt

Here is os.environ for test in VSCode: test_os_environ.txt
Here is os.environ for lab in Jupyterlab: lab_os_environ.txt

You'll see 'PYTHONNOUSERSITE': 'True' in both environments.

@DonJayamanne
Copy link
Contributor

@parodayco looking at the logs you seem to be using two separate venvs, one named lab for Jupyter lab & one named test for VS code, please could you use the same one for both and re-send both sets of logs (vscode logs & environ from both).

@DonJayamanne
Copy link
Contributor

@parodayco as suspected its the env variables and based on the docs here https://github.com/ibmdb/python-ibmdb#installation
you need to setup the env variable DYLD_LIBRARY_PATH to get things working. This isn't available when running VS Code, hence things fall over.

In your case it works for Jupyter lab as this is setup somewhere in one of your shell login scripts.
Applications launched from VS Code do not source login shells (tha'ts basically how applications are launched on macs), thus these env variables are not available to these apps.

Please create a file named .env your workspace folder and add the following value (reload VS Code) and it should work:

DYLD_LIBRARY_PATH'=/usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11:/Applications/dsdriver/lib:

@DonJayamanne
Copy link
Contributor

DonJayamanne commented Apr 13, 2022

Please let me know how that goes.
Also considering the fact that ibm_db doesn't work (hopefully it will work going forward) have you continue using VS Code. I'd like to understand how this bug impacted your usage of the Jupyter extension or VS Code overall. Did you continue using it for other tasks such as editing or the like?

The feed back here would help so that we can prioritize such issues in the future.

@parodayco
Copy link
Author

@DonJayamanne I created an .env file in my Projects folder with the DYLD_LIBRARY_PATH hard-coded and ibm_db.connect() now works in VSCode Jupyter. Hallelujah!

I use VS Code all the time since I run many notebooks that do not depend on a Db2 connection. To be honest, I use jaydebeapi on my laptop but wished to use ibm-db since it's the default connector in our production environment. Now I can edit and run the same notebook code in both places. Thank you so much for you help.

My only feedback is that your documentation could do better at explaining how VS Code reads env variables, since it has very specific limitations and requirements. I originally believed that VS Code was reading my .zshenv file correctly because I see this in my test.ipynb:

!echo $DYLD_LIBRARY_PATH
/usr/local/Cellar/gcc/11.2.0_3/lib/gcc/11:/Applications/dsdriver/lib:

...yet the kernel crashed when I ran ibm_db.connect()

VS Code requires me to store that DYLD_LIBRARY_PATH in an .env file in my VS Code workspace. When I restart VS Code and run !echo $DYLD_LIBRARY_PATH, I see the same output but the kernel no longer crashes.

Any way, thank you again for all your patience and help. I appreciate it immensely.

@DonJayamanne
Copy link
Contributor

DonJayamanne commented Apr 14, 2022

thanks for the feedback and confirming the fix

@micxael
Copy link

micxael commented Sep 27, 2022

@DonJayamanne

debug 09:57:30.211: VSCodeNotebookController::handleExecution, Class name = j (started execution)
debug 09:57:30.212: Execute Cell 0 /home/jae/Dropbox/USC/Fall2022/KG/CronKGQA/cronkgqa_testing.ipynb
debug 09:57:30.212: start the kernel, options.disableUI=false
debug 09:57:30.212: Start Jupyter Session in kernel.ts with disableUI = false
debug 09:57:31.528: KernelProcess Exit Exit - undefined /home/jae/anaconda3/envs/cronkgqa/lib/python3.8/site-packages/traitlets/traitlets.py:2202: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use 'hmac-sha256' instead of '"hmac-sha256"' if you require traitlets >=5.
  warn(
/home/jae/anaconda3/envs/cronkgqa/lib/python3.8/site-packages/traitlets/traitlets.py:2157: FutureWarning: Supporting extra quotes around Bytes is deprecated in traitlets 5.0. Use 'c34807f0-d2e4-47bf-a25a-4bc3305b62a7' instead of 'b"c34807f0-d2e4-47bf-a25a-4bc3305b62a7"'.
  warn(

error 09:57:31.529: Disposing session as kernel process died ExitCode: undefined, Reason: /home/jae/anaconda3/envs/cronkgqa/lib/python3.8/site-packages/traitlets/traitlets.py:2202: FutureWarning: Supporting extra quotes around strings is deprecated in traitlets 5.0. You can use 'hmac-sha256' instead of '"hmac-sha256"' if you require traitlets >=5.
  warn(
/home/jae/anaconda3/envs/cronkgqa/lib/python3.8/site-packages/traitlets/traitlets.py:2157: FutureWarning: Supporting extra quotes around Bytes is deprecated in traitlets 5.0. Use 'c34807f0-d2e4-47bf-a25a-4bc3305b62a7' instead of 'b"c34807f0-d2e4-47bf-a25a-4bc3305b62a7"'.
  warn(

info 09:57:31.529: Dispose Kernel process 38954.
error 09:57:31.529: Raw kernel process exited code: undefined
debug 09:57:31.529: shutdownSession b74819e2-d956-4e1a-83ca-e0d1b648e48f, .cronkgqa./home/jae/anaconda3/envs/cronkgqa/bin/python3.8./home/jae/anaconda3/envs/cronkgqa/bin/python3.8.-m#ipykernel_launcher - start
debug 09:57:31.529: Session can be shutdown .cronkgqa./home/jae/anaconda3/envs/cronkgqa/bin/python3.8./home/jae/anaconda3/envs/cronkgqa/bin/python3.8.-m#ipykernel_launcher
debug 09:57:31.530: Disposed Kernel process 38954.
error 09:57:31.530: Error in waiting for cell to complete [Error: Canceled future for execute_request message before replies were done
	at t.KernelShellFutureHandler.dispose (/home/jae/.vscode/extensions/ms-toolsai.jupyter-2022.9.1002511105/out/extension.node.js:2:32353)
	at /home/jae/.vscode/extensions/ms-toolsai.jupyter-2022.9.1002511105/out/extension.node.js:2:51405
	at Map.forEach (<anonymous>)
	at y._clearKernelState (/home/jae/.vscode/extensions/ms-toolsai.jupyter-2022.9.1002511105/out/extension.node.js:2:51390)
	at y.dispose (/home/jae/.vscode/extensions/ms-toolsai.jupyter-2022.9.1002511105/out/extension.node.js:2:44872)
	at /home/jae/.vscode/extensions/ms-toolsai.jupyter-2022.9.1002511105/out/extension.node.js:2:2201048
	at t.swallowExceptions (/home/jae/.vscode/extensions/ms-toolsai.jupyter-2022.9.1002511105/out/extension.node.js:7:130819)
	at p.dispose (/home/jae/.vscode/extensions/ms-toolsai.jupyter-2022.9.1002511105/out/extension.node.js:2:2201026)
	at t.RawSession.dispose (/home/jae/.vscode/extensions/ms-toolsai.jupyter-2022.9.1002511105/out/extension.node.js:2:2206134)
	at process.processTicksAndRejections (node:internal/process/task_queues:96:5)]
warn 09:57:31.530: Cell completed with errors {
  message: 'Canceled future for execute_request message before replies were done'
}
info 09:57:31.531: Cancel all remaining cells true || Error || undefined
debug 09:57:31.531: Cancel pending cells
debug 09:57:31.532: Cell 0 executed with state Error
debug 09:57:31.533: VSCodeNotebookController::handleExecution, Class name = j, completed in 1322ms, has a falsy return value
debug 09:57:31.533: shutdownSession b74819e2-d956-4e1a-83ca-e0d1b648e48f, .cronkgqa./home/jae/anaconda3/envs/cronkgqa/bin/python3.8./home/jae/anaconda3/envs/cronkgqa/bin/python3.8.-m#ipykernel_launcher - shutdown complete

Is the issue in the log above related to this? Thank you!

@DonJayamanne
Copy link
Contributor

no idea, please try the solution described above

@jamsden
Copy link

jamsden commented May 17, 2023

I cannot get ibm_db to work in vs code on macOS. My notebook runs fine in jupyter lab, but attempting to connect to a database crashes the kernel in vs code. I think the reason is that environment variable DYLD_LIBRARY_PATH isn't defined in vs code. I have attempted to fix that with a .env file, launch.json, and using python-dotenv. Nothing seems to get that environment variable set properly. The solution above doesn't provide enough details on what should be in the .env file, where it should be located, how to ensure vs code loads it, and how to ensure the DYLD_LIBRARY_PATH is set before attempting to connect to a database. Can someone help?

@DonJayamanne
Copy link
Contributor

@jamsden
Copy link

jamsden commented May 18, 2023

.env loading doesn't work with python 3.10.8 which is what is currently shipping with anaconda.

What I found is that print(os.getenv("DYLD_LIBRARY_PATH")) in a jupyter notebook running in vscode works if the kernel is /usr/local/bin/python3 which is Python3.8.10 on my macOS Ventura platform. But it does not work if I use a virtual environment using that same python version, or any other python version I have or any other environment.

@jamsden
Copy link

jamsden commented Jun 23, 2023

Actually what I found is that Apple SIP is stripping all DYLD_* environment variables out of the .env file. ibm_db works in a .py file run in VS Code, but the same Python code in a jupyter notebook crashes the kernel because DYLD_LIBRARY_PATH is not defined, no matter what I try to do. This might have something to do with entitlements and needs:

<key>com.apple.security.cs.disable-library-validation</key>
<true/>
<key>com.apple.security.cs.allow-dyld-environment-variables</key>
<true/>

The issue might be that VS Code is not sending DYLD_LIBRARY_PATH to the jupyter notebook subprocess when it starts its kernel. I have tried setting that environment variable from .zprofile, in a .env file loaded by vscode, in the kernel.json file, and using a %env magic in the notebook. In all cases, ibm_db still crashes. It appears DYLD_LIBRARY_PATH is stripped from the environment or not passed to ibm_db running in a jupyter notebook in all cases.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 30, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
info-needed Issue requires more information from poster
Projects
None yet
Development

No branches or pull requests

7 participants