How to configure Jupyter console ports - jupyter

I'm trying to run jupyter console in a Linux docker image, and connect to from the host OS (Windows). To do this, I must specify the used ports so that docker publishes them. I cannot use --network host, since my host OS is Windows (docs). So I must know before hand which ports to publish. I have tried a few approaches, but none of them seem to work:
$ jupyter console --shell=6001 --iopub=6002 --stdin=6003 --control=6004 --hb=6005
Jupyter console 6.4.3
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:08:53)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: %connect_info
{
"shell_port": 41847,
"iopub_port": 36575,
"stdin_port": 43621,
"control_port": 49365,
"hb_port": 41115,
"ip": "127.0.0.1",
"key": "f1c2fc92-1e1ac00bfa0797516ce51331",
"transport": "tcp",
"signature_scheme": "hmac-sha256",
"kernel_name": ""
}
And:
$ jupyter console --generate-config
Writing default config to: /root/.jupyter/jupyter_console_config.py
$ nano /root/.jupyter/jupyter_console_config.py # Configure c.ConnectionFileMixin.control_port etc.
$ jupyter console
Jupyter console 6.4.3
Python 3.7.12 | packaged by conda-forge | (default, Oct 26 2021, 06:08:53)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.31.1 -- An enhanced Interactive Python. Type '?' for help.
In [1]: %connect_info
{
"shell_port": 40717,
"iopub_port": 49261,
"stdin_port": 46105,
"control_port": 47223,
"hb_port": 44913,
"ip": "127.0.0.1",
"key": "ee31c87f-ceb16a5b2c752085b9577677",
"transport": "tcp",
"signature_scheme": "hmac-sha256",
"kernel_name": ""
}
Any suggestions are welcome. I must say I'm a Jupyter beginner, I'm not even quite sure what is the difference between starting a console and a notebook. My goal is to run a Spyder IDE on Windows but execute the code (via an IPython session) inside the docker container.
Edit 1: I tested this on a different machine, and interestingly the command line arguments seem to work!
$ jupyter console --shell=6001 --iopub=6002 --stdin=6003 --control=6004 --hb=6005
Jupyter console 6.4.0
Python 3.8.0 (default, Nov 6 2019, 21:49:08)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.19.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: %connect_info
{
"shell_port": 6001,
"iopub_port": 6002,
"stdin_port": 6003,
"control_port": 6004,
"hb_port": 6005,
"ip": "127.0.0.1",
"key": "904874f1-cd228fd7436e99d56d83ac81",
"transport": "tcp",
"signature_scheme": "hmac-sha256",
"kernel_name": ""
}
Is this just a bug in the older version of jupyter / ipython?
Edit 2: Using newer Python and Jupyter on Linux doesn't seem to fix this:
# jupyter --version
Selected Jupyter core packages...
IPython : 8.6.0
ipykernel : 6.17.0
ipywidgets : 8.0.2
jupyter_client : 7.3.4
jupyter_core : 4.11.2
jupyter_server : 1.23.0
jupyterlab : 3.5.0
nbclient : 0.7.0
nbconvert : 7.2.3
nbformat : 5.7.0
notebook : 6.5.2
qtconsole : 5.4.0
traitlets : 5.5.0
# jupyter console --shell=6001 --iopub=6002 --stdin=6003 --control=6004 --hb=6005
Jupyter console 6.4.4
Python 3.9.13 (main, Oct 13 2022, 21:15:33)
Type 'copyright', 'credits' or 'license' for more information
IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: %connect_info
{
"shell_port": 42637,
"iopub_port": 58425,
"stdin_port": 38171,
"control_port": 54103,
"hb_port": 52349,
"ip": "127.0.0.1",
"key": "b73514a7-0a23b4918cf72d63f13a0577",
"transport": "tcp",
"signature_scheme": "hmac-sha256",
"kernel_name": ""
}
Edit 3, yet an other test. This time on Windows:
>jupyter --version
Selected Jupyter core packages...
IPython : 8.6.0
ipykernel : 6.17.0
ipywidgets : 8.0.2
jupyter_client : 7.3.4
jupyter_core : 4.11.2
jupyter_server : 1.23.0
jupyterlab : not installed
nbclient : 0.7.0
nbconvert : 7.2.3
nbformat : 5.7.0
notebook : 6.5.2
qtconsole : 5.4.0
traitlets : 5.5.0
>jupyter console --shell=6001 --iopub=6002 --stdin=6003 --control=6004 --hb=6005
C:\vendor\Anaconda3\envs\tpa\lib\site-packages\zmq\_future.py:679: RuntimeWarning: Proactor event loop does not implement add_reader family of methods required for zmq. Registering an additional selector thread for add_reader support via tornado. Use `asyncio.set_event_loop_policy(WindowsSelectorEventLoopPolicy())` to avoid this warning.
self._get_loop()
Jupyter console 6.4.4
Python 3.9.13 (main, Oct 13 2022, 21:23:06) [MSC v.1916 64 bit (AMD64)]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.6.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: %connect_info
{
"shell_port": 4048,
"iopub_port": 4049,
"stdin_port": 4050,
"control_port": 4052,
"hb_port": 4051,
"ip": "127.0.0.1",
"key": "463250f7-86ba2e10420dbc3869f8f2ac",
"transport": "tcp",
"signature_scheme": "hmac-sha256",
"kernel_name": ""
}
I haven't yet figured out a pattern on when the port config is respected and when it isn't. :(

Related

How to debug an ARM Linux device with VSCode on a Windows host

I try to remote debug an ARM Linux embedded device with Native Debug in VSCode on a Windows host (no WSL).
Host launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "gdb",
"request": "attach",
"name": "gdb",
"executable": "${workspaceRoot}\\myprogram\\myprogram ",
"stopAtConnect": true,
"target": "192.168.xxx.xxx:2000",
"remote": true,
"cwd": "${workspaceRoot}/myprogram",
"gdbpath": "C:\\msys64\\mingw64\\bin\\gdb-multiarch.exe",
"debugger_args": ["-iex", "set osabi none"],
}
]
}
Target
debarm:~# gdbserver --version
GNU gdbserver (GDB) 7.0.1-debian
Copyright (C) 2009 Free Software Foundation, Inc.
gdbserver is free software, covered by the GNU General Public License.
This gdbserver was configured as "arm-linux-gnueabi"
debarm:~# gdbserver :2000 --attach 1966
Attached; pid = 1966
Listening on port 2000
Remote debugging from host 192.168.xxx.xxx
However, stepping gives warning: Remote failure reply: E01 similar to: GDB remote debugging fails with error E01
I also tried the arm-none-eabi-gdb.exe from https://developer.arm.com/downloads/-/gnu-rm but it gives the same problem.
I also tried the arm-linux-gnueabi-gdb.exe from https://releases.linaro.org/components/toolchain/binaries/latest-5/arm-linux-gnueabi/ but it gives Error while reading shared library symbols for target:/lib/ld-linux.so.3.
Any suggestions for what the problem is with this approach?
Got it working with Linaro arm-linux-gnueabi-gdb.exe and adding "-iex", "set auto-solib-add 0" to debugger_args in launch.json.

CISCO IOS-XR, Python3.7, Not able to run commands like 'ls' and 'df' on Cisco router

Cisco ios-xr router using CLI:
RP/0/RP0#show version
Thu Nov 25 07:53:59.103 UTC
Cisco IOS XR Software, Version 6.5.32.11I
Copyright (c) 2013-2020 by Cisco Systems, Inc.
RP/0/RP0#run
Thu Nov 25 07:54:05.231 UTC
[xr-vm_node0_RP0_CPU0:~]$df
Filesystem 1K-blocks Used Available Use% Mounted on
rootfs 3966080 1332040 2412860 36% /
76892 11848320 43% /mnt/ecu/vdd
[xr-vm_node0_RP0_CPU0:~]$
Using python:
I am able to run show commands using Connecthandler .send.command:
from netmiko import ConnectHandler
import subprocess
Network_Device = {"host": "10.111.22.333", "username": "USER123", "password": "Pass123", "device_type": "cisco_xr",}
Connect = ConnectHandler(**Network_Device)
Connect.enable()
version1 = "show version"
print(Connect.send_command(version1))
But not able to run 'df' or 'ls' commands, as not able to reach bash prompt i reach by running 'run' command on router.
I tried:
disk1files = subprocess.run("df", stdout=subprocess.PIPE)
print(disk1files.stdout.decode())
But seems its wrong. Please suggest the right library or code I can use here.
This is my first question here, so bear some silly questions or mistakes done in code
if on DF you are referring to "Don't fragment" then it is posible to send it like
Connect.send_command("ping 192.168.10.10 df-bit size 1600")
where 1600 represents MTU, and for ls commands is link command,
Connect.send_command("ls-active")
Connect.send_command("ls-active-enabled")
but if you are referring to df and ls in linux (disk free and list files..) then you can use os module for sending commands:
import os
os.system("ls -l")
or use call from subprocess module:
from subprocess import call
call(["ls", "-l"])
If you need to acccess cisco bash:
switch# configure terminal
switch(config)# feature bash-shell
switch# run?
run Execute/run program
run-script Run shell scripts
switch# run bash?
bash Linux-bash
switch# run bash
bash-4.2$ whoami
admin
bash-4.2$ pwd
/bootflash/home/admin
bash-4.2$

Httpie hangs in Git Bash terminal on Windows 10

According to the official documentation httpie tool also works on Windows 10, however when I run the command in terminal it simply hangs and nothing happens:
$ http :8000/
Is there an explanation what is going on and preferably a workaround?
I was able to get a hint by appending the --debug parameter:
$ http localhost:8000 --debug
HTTPie 0.9.9
Requests 2.12.4
Pygments 2.1.3
Python 3.4.4 (v3.4.4:737efcadf5a6, Dec 20 2015, 20:20:57) [MSC v.1600 64 bit (AMD64)]
c:\users\...\venv\scripts\python.exe
Windows 10
<Environment {
"colors": 256,
"config": {
"__meta__": {
"about": "HTTPie configuration file",
"help": "https://httpie.org/docs#config",
"httpie": "0.9.9"
},
"default_options": "[]"
},
"config_dir": "C:\\Users\\...\\AppData\\Roaming\\\\httpie",
"is_windows": true,
"stderr": "<colorama.ansitowin32.StreamWrapper object at 0x0000000003CDAB00>",
"stderr_isatty": false,
"stdin": "<_io.TextIOWrapper name='<stdin>' mode='r' encoding='cp1252'>",
"stdin_encoding": "cp1252",
"stdin_isatty": false,
"stdout": "<colorama.ansitowin32.StreamWrapper object at 0x0000000003CDA9B0>",
"stdout_encoding": "cp1252",
"stdout_isatty": false
}>
The crucial point is that the isatty related option is set to false.
I was able to resole it and getting http working as expected by prepending the winpty command:
$ winpty http :8000
HTTP/1.0 200 OK
Content-Type: application/json
Date: Fri, 16 Dec 2016 19:56:58 GMT
Server: WSGIServer/0.2 CPython/3.4.4
X-Frame-Options: SAMEORIGIN
{
"status": "ok"
}
Solution:
By adding this alias line
alias http='winpty http'
to the ~/.profile file, one can use the initial command http as expected with git bash.

Can't add 1+1 in ipython notebook

Since some updates of ipython and efforts to install R in jupyter I just can't even add 1 and 1:
1+1 just yields no output in a python notebook (jupyter).
The console from where the notebook is launched indicates some problem with IPKernel App ...
$ jupyter notebook
[I 16:15:44.792 NotebookApp] Serving notebooks from local directory: /home/jeanpat
[I 16:15:44.792 NotebookApp] 0 active kernels
[I 16:15:44.792 NotebookApp] The IPython Notebook is running at: http://localhost:8888/
[I 16:15:44.792 NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).
(process:11705): GLib-CRITICAL **: g_slice_set_config: assertion 'sys_page_size == 0' failed
[I 16:15:50.325 NotebookApp] Kernel started: 50c937a7-9ab6-456f-8e65-6d7de55301a6
[IPKernelApp] ERROR | No such comm target registered: ipython.widget
[I 16:17:50.327 NotebookApp] Saving file at /Untitled.ipynb
However 1+1 yields 2 if executed in an ipython console:
~$ ipython
Python 2.7.9 (default, Apr 2 2015, 15:33:21)
Type "copyright", "credits" or "license" for more information.
IPython 4.0.0 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: 1+1
Out[1]: 2
Removing ~/.local/share/jupyter fixed the problem. Running with the debug mode (jupyter notebook --debug) showed where jupyter was looking for its kernels. – Jean-Pat 2 hours ago

ipython style tab complete with ipdb for imported modules

I'm trying to get ipython style table complete with pdb by using ipdb.
On a clean ubuntu 14.04 install (new aws instance) I run.
sudo apt-get update
sudo apt-get upgrade -y
sudo apt-get install python-setuptools
sudo easy_install pip
sudo pip install ipython
sudo pip install ipdb
sudo pip install boto
Then boot up ipython, and try.
ubuntu#ip-10-0-0-244:~$ ipython
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
Type "copyright", "credits" or "license" for more information.
IPython 2.3.1 -- An enhanced Interactive Python.
? -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help -> Python's own help system.
object? -> Details about 'object', use 'object??' for extra details.
In [1]: import ipdb
In [2]: import boto
In [3]: ipdb.set_trace()
--Call--
> /usr/local/lib/python2.7/dist-packages/IPython/core/displayhook.py(234)__call__()
233
--> 234 def __call__(self, result=None):
235 """Printing with history cache management.
ipdb> str.
str.capitalize str.encode str.format str.isdigit str.isupper str.lstrip str.rfind str.rsplit str.startswith str.translate
str.center str.endswith str.index str.islower str.join str.mro str.rindex str.rstrip str.strip str.upper
str.count str.expandtabs str.isalnum str.isspace str.ljust str.partition str.rjust str.split str.swapcase str.zfill
str.decode str.find str.isalpha str.istitle str.lower str.replace str.rpartition str.splitlines str.title
ipdb> boto.
boto.[tab] just sits there. If I'm reading the docs right this should work, but maybe I have miss-understood something.
If I define a simple script test.py
import boto
print(boto.__version__)
Then call:
ubuntu#ip-10-0-0-244:~$ python -m ipdb test.py
> /home/ubuntu/test.py(1)<module>()
----> 1 import boto
2
3 print(boto.__version__)
ipdb> n
> /home/ubuntu/test.py(3)<module>()
1 import boto
2
----> 3 print(boto.__version__)
ipdb> boto.
boto.BUCKET_NAME_RE boto.connect_autoscale boto.connect_emr boto.connect_s3 boto.os
boto.BotoConfigLocations boto.connect_beanstalk boto.connect_euca boto.connect_sdb boto.perflog
boto.BucketStorageUri boto.connect_cloudformation boto.connect_fps boto.connect_ses boto.platform
boto.Config boto.connect_cloudfront boto.connect_glacier boto.connect_sns boto.plugin
boto.ENDPOINTS_PATH boto.connect_cloudsearch boto.connect_gs boto.connect_sqs boto.pyami
boto.FileStorageUri boto.connect_cloudsearch2 boto.connect_ia boto.connect_sts boto.re
boto.GENERATION_RE boto.connect_cloudtrail boto.connect_iam boto.connect_support boto.regioninfo
boto.InvalidUriError boto.connect_cloudwatch boto.connect_kinesis boto.connect_swf boto.resultset
boto.NullHandler boto.connect_cognito_identity boto.connect_logs boto.connect_vpc boto.s3
boto.TOO_LONG_DNS_NAME_COMP boto.connect_cognito_sync boto.connect_mturk boto.connect_walrus boto.set_file_logger
boto.UserAgent boto.connect_directconnect boto.connect_opsworks boto.datetime boto.set_stream_logger
boto.VERSION_RE boto.connect_dynamodb boto.connect_rds boto.exception boto.storage_uri
boto.Version boto.connect_ec2 boto.connect_rds2 boto.handler boto.storage_uri_for_key
boto.boto boto.connect_ec2_endpoint boto.connect_redshift boto.init_logging boto.sys
boto.compat boto.connect_elastictranscoder boto.connect_route53 boto.log boto.urlparse
boto.config boto.connect_elb boto.connect_route53domains boto.logging boto.vendored
I get the behavior I'd like.
Does anyone know how to make the tab complete functionality work for the set_trace() work case?
-Thanks