These are chat archives for ipython/ipython

25th
Mar 2015
Armin Burgmeier
@aburgm
Mar 25 2015 16:23
From within IPython, is there a straightforward/encouraged way to find out whether my code is running in a ZMQ kernel?
Min RK
@minrk
Mar 25 2015 16:40
@aburgm from IPython import get_ipython; in_kernel = hasattr(get_ipython(), 'kernel')
Armin Burgmeier
@aburgm
Mar 25 2015 16:43
and then check whether get_ipython().kernel is an instance of IPython.kernel.zmq.ipkernel.IPythonKernel?
Jonathan Frederic
@jdfreder
Mar 25 2015 17:31
@Carreau @takluyver I'm going to submit the proposal for SciPy, sounds good?
Matthias Bussonnier
@Carreau
Mar 25 2015 17:44
Sounds good to me.
Min RK
@minrk
Mar 25 2015 17:46
@abeguerra just whether it exists is good enough.
Thomas Kluyver
@takluyver
Mar 25 2015 17:47
@jdfreder Yep, thanks!
Armin Burgmeier
@aburgm
Mar 25 2015 17:52
@minrk okay, perfect, thanks!
Kyle Kelley
@rgbkrk
Mar 25 2015 18:14
Since the split is happening, I just pinned our docker images that derive from ipython/ipython to use the 3.x branch
ipython/docker-notebook#42
Jonathan Frederic
@jdfreder
Mar 25 2015 18:17
@takluyver @Carreau hmm the template does not map 1-to-1 with the submission process...
jdfreder @jdfreder sighs
Matthias Bussonnier
@Carreau
Mar 25 2015 18:18
hum...
complex to redo or not ?
Jonathan Frederic
@jdfreder
Mar 25 2015 18:18
It doesn't no
I'm wiggling stuff into place
Matthias Bussonnier
@Carreau
Mar 25 2015 18:18
I'll trust you then.
Jonathan Frederic
@jdfreder
Mar 25 2015 18:18
I need to write a Python script to check if their env is setup : )
I'm doing that now.
Matthias Bussonnier
@Carreau
Mar 25 2015 18:19
:-)
Min RK
@minrk
Mar 25 2015 18:20
@rgbkrk thanks
Thomas Kluyver
@takluyver
Mar 25 2015 18:23
assert sys.version_info[0] >= 3 :)
Jason Grout
@jasongrout
Mar 25 2015 18:29
wow, you guys are on a roll with The Big Split. Awesome!
Sylvain Corlay
@SylvainCorlay
Mar 25 2015 18:30
This message was deleted
Armin Burgmeier
@aburgm
Mar 25 2015 19:01
If I run the example notebook there in IPython 3.0, the output from the first cell shows up in the second one
some don't show up at all... it looks a bit race-y
Jonathan Frederic
@jdfreder
Mar 25 2015 19:16
@takluyver @Carreau the tutorial has been submitted. Stupid website DCed while I was writing the environment verification script so I had to re-enter everything :angry: .
Kyle Kelley
@rgbkrk
Mar 25 2015 19:18
@jhamrick, I submitted your post to http://www.reddit.com/r/docker
It's on top for now
I just noticed that Audrey Greenfield submitted it to /r/pyladies
so that's super cool
Jessica B. Hamrick
@jhamrick
Mar 25 2015 19:22
Awesome :D
Kyle Kelley
@rgbkrk
Mar 25 2015 19:29
One of us should probably mention it on the mailing list, since not everyone is on twitter
Jessica B. Hamrick
@jhamrick
Mar 25 2015 19:30
Good idea
I can, I suppose
Remi Rampin
@remram44
Mar 25 2015 19:31
Can I always assume that the current .ipynb file is in os.getcwd()?
Jessica B. Hamrick
@jhamrick
Mar 25 2015 19:32
It is possible for that to not be the case, but those should be pretty rare circumstances, so I’d say probably yeah
Remi Rampin
@remram44
Mar 25 2015 19:37
well it's not like I know another way of getting the path to the .ipynb :cry:
Jessica B. Hamrick
@jhamrick
Mar 25 2015 19:37
Hmm, I wonder if __file__ works in the notebook?
Nope
I would say it’s probably safe to assume that the .ipynb is in the cwd, though
It is probably just good to be aware that there is a remote possibility that might not be the case
The case in which it wouldn’t be is if you were running the notebook from the command line and manually set the cwd of the kernel
Min RK
@minrk
Mar 25 2015 20:05
It's safe to assume that at the start of the notebook. You need to be wary of cd calls later on, though.
We've thought about putting __file__ in the namespace for kernels associated with a notebook, but that gets a little tricky when you rename notebooks.
I'm not sure it's super important to update along with renames without restarting the kernel, though.
Patrick Brockmann
@PBrockmann
Mar 25 2015 20:44
Testing jupyterhub... Does jupyterhub produce a log file as apache http server ?
Min RK
@minrk
Mar 25 2015 21:09
If you specify --log-file=/path/to/file.log
or redirect stderr with jupyterhub 2> /some/file.log
Patrick Brockmann
@PBrockmann
Mar 25 2015 21:15
Oups. Sorry for this stupid question. It is perfectly documented from jupyterhub --help
Nathan Goldbaum
@ngoldbaum
Mar 25 2015 21:23
my IPython 3.0 install started complaining about not being able to see the mathjax CDN today. Is this just an intermittent issue with mathjax or could this indicate some sort of configuration issue on my end?
i guess installing mathjax in my local profile couldn't hurt...
Min RK
@minrk
Mar 25 2015 21:27
@ngoldbaum CDN url appears to be working now, so probably an intermittent issue
Jonathan Frederic
@jdfreder
Mar 25 2015 22:08

@rgbkrk I'm setting up nginx in front of JHub in a manner very similar to tmpnb. When trying to access a notebook, the websocket proxy fails with a 502 (JS console). My nginx error log reads

2015/03/25 14:51:12 [error] 12987#0: *107 upstream prematurely closed connection while reading response header from upstream, client: 127.0.0.1, server: , request: "GET /user/jon/api/kernels/cc94a463-c09b-41f8-a825-c139d9adc707/channels?session_id=4114CF021DD044179A043BD4C31F7626 HTTP/1.1", upstream: "http://127.0.0.1:8000/user/jon/api/kernels/cc94a463-c09b-41f8-a825-c139d9adc707/channels?session_id=4114CF021DD044179A043BD4C31F7626", host: "localhost:777"

and my JHub log reads

[W 2015-03-25 15:05:14.091 jon zmqhandlers:145] Blocking Cross Origin WebSocket Attempt.  Origin: http://127.0.0.1:777, Host: 127.0.0.1
Blocking Cross Origin WebSocket Attempt is the key.
Kyle Kelley
@rgbkrk
Mar 25 2015 22:09
Are you accessing it client side as 127.0.0.1:777 ?
Jonathan Frederic
@jdfreder
Mar 25 2015 22:09
You'd think localhost:777 is a valid domain.
Kyle Kelley
@rgbkrk
Mar 25 2015 22:09
Hmmm
Jonathan Frederic
@jdfreder
Mar 25 2015 22:09
I've tried both 127.0.0.1 and localhost
Kyle Kelley
@rgbkrk
Mar 25 2015 22:09
I'm guessing chrome (or FF) is sending Origin as 127.0.0.1:777 and Host as 127.0.0.1
Which is a mismatch to our server checks
Are you able to run on port 80 at all?
Jonathan Frederic
@jdfreder
Mar 25 2015 22:10
I'll give it a try, one sec.
Kyle Kelley
@rgbkrk
Mar 25 2015 22:10
If that fixes it, maybe we need to lessen the strictness
My thinking on keeping the port was that other services shouldn't be able to access the notebook server
Jonathan Frederic
@jdfreder
Mar 25 2015 22:12
Bare with me, I have a runaway nginx using port 80 already : /
Go figure...
Kyle Kelley
@rgbkrk
Mar 25 2015 22:12
of course
:P
The alternative here is to change the check origin in your ipython notebook config
This is a protection for local non-authed ipython notebook servers anyway
Nathan Goldbaum
@ngoldbaum
Mar 25 2015 22:13
@minrk hmm, still seems to be happening. Maybe a network issue on this cluster? Thanks for the reply :)
Jonathan Frederic
@jdfreder
Mar 25 2015 22:15
@rgbkrk running on port 80 fixes the problem! Thanks.
Kyle Kelley
@rgbkrk
Mar 25 2015 22:15
Yeah
Jonathan Frederic
@jdfreder
Mar 25 2015 22:15
Still, I may want to run this on another port...
Kyle Kelley
@rgbkrk
Mar 25 2015 22:15
Yeah...
hold on a sec here
Jonathan Frederic
@jdfreder
Mar 25 2015 22:15
How difficult is it for us to relax the xdomain security. Is that okay? @minrk
Just to allow it to work for different ports
Kyle Kelley
@rgbkrk
Mar 25 2015 22:18
How about c.NotebookApp.allow_origin_pat = r'127.0.0.1(:\d+)?'
Translated to whatever works for Python
Jonathan Frederic
@jdfreder
Mar 25 2015 22:20
That doesn't seem to work
but I have a feeling the config is getting passed to the spawned server
via the spawner
because the equivalent is jupyterhub --NotebookApp.allow_origin_pat='127.0.0.1(:\d+)?'
I also tried jupyterhub --NotebookApp.allow_origin_pat='127.0.0.1(:\\d+)?'
because I wasn't sure if the backslash needed to be escaped.
Kyle Kelley
@rgbkrk
Mar 25 2015 22:25
That should be r'127\.0\.0\.1(\:\d+)?'
without the r that is
since it's in the shell
gross
Jonathan Frederic
@jdfreder
Mar 25 2015 22:30
Still a no go
I'll debug it to see if it's being set correctly
Jonathan Frederic
@jdfreder
Mar 25 2015 22:38
Yeah, the config you gave me isn't working because the spawner isn't passing that config to the spawnees
I should be able to get it there another way though... one sec.
Kyle Kelley
@rgbkrk
Mar 25 2015 22:39
yuck
Jonathan Frederic
@jdfreder
Mar 25 2015 22:43
@rgbkrk jesus
that's an ugly launch cmd
jupyterhub --Spawner.cmd="['jupyterhub-singleuser', '--NotebookApp.allow_origin_pat=\'127\.0\.0\.1(:\d+)?\'']"
Still doesn't work though... : (
Here's the regex that's recieved:
[W 2015-03-25 15:42:40.430 jon notebookapp:838] XXX
[W 2015-03-25 15:42:40.430 jon notebookapp:839] 127\.0\.0\.1(:\d+)?
(Or removing the logging crap 127\.0\.0\.1(:\d+)?)
Kyle Kelley
@rgbkrk
Mar 25 2015 22:45
That looks right and works in my terminal
Jonathan Frederic
@jdfreder
Mar 25 2015 22:46
The error is still "[W 2015-03-25 15:45:42.958 jon zmqhandlers:148] Blocking Cross Origin WebSocket Attempt. Origin: http://127.0.0.1:777, Host: 127.0.0.1
"
Kyle Kelley
@rgbkrk
Mar 25 2015 22:46
>>> re.match(r'127\.0\.0\.1(:\d+)?', '127.0.0.1')
<_sre.SRE_Match object at 0x1098e3288>
>>> re.match(r'127\.0\.0\.1(:\d+)?', '127.0.0.2')
>>> re.match(r'127\.0\.0\.1(:\d+)?', '127.0.0.1:8888')
<_sre.SRE_Match object at 0x1098e3210>
>>> re.match(r'127\.0\.0\.1(:\d+)?', '127.0.0.1:8000')
<_sre.SRE_Match object at 0x1098e3288>
Someone in this room should shoot me for using vanilla python
;)
Jonathan Frederic
@jdfreder
Mar 25 2015 22:46
LOL
Min RK
@minrk
Mar 25 2015 22:46
Yeah, using config files is definitely better
Jonathan Frederic
@jdfreder
Mar 25 2015 22:48
We'll regardless, the right value is being set for NotebookApp.allow_origin_pat, all my URLs including the one in the browser point to 127.0.0.1 and it still doesn't fix the problem. I'll debug some more...
Jonathan Frederic
@jdfreder
Mar 25 2015 22:53
@rgbkrk
[W 2015-03-25 15:52:01.394 jon zmqhandlers:144] http://127.0.0.1:777
[W 2015-03-25 15:52:01.395 jon zmqhandlers:145] re.compile('127\\.0\\.0\\.1(:\\d+)?')
[W 2015-03-25 15:52:01.396 jon zmqhandlers:146] None
Interesting...
            self.log.warn(str(origin))
            self.log.warn(str(self.allow_origin_pat))
            self.log.warn(str(self.allow_origin_pat.match(origin)))
in zmqhandlers.py
Min RK
@minrk
Mar 25 2015 22:54
origin includes protocol
Jonathan Frederic
@jdfreder
Mar 25 2015 22:54
Ah!
So the correct command is...
wait for it...
jupyterhub --Spawner.cmd="['jupyterhub-singleuser', '--NotebookApp.allow_origin_pat=\'http://127\.0\.0\.1(:\d+)?\'']"
Min RK
@minrk
Mar 25 2015 22:55
There's too many names: host = hostname + port, origin = proto + host
Yeah, putting it on the command-line probably isn't the way to go
Jonathan Frederic
@jdfreder
Mar 25 2015 22:55
Hehe I know
@minrk (or @rgbkrk ) is there any other obviousness I'm missing? I feel like I need regex 101
[W 2015-03-25 15:56:38.120 jon zmqhandlers:144] http://localhost:777
[W 2015-03-25 15:56:38.120 jon zmqhandlers:145] re.compile('http://127\\.0\\.0\\.1(:\\d+)?')
[W 2015-03-25 15:56:38.120 jon zmqhandlers:146] None
That's produced by the same code
still regexpal shows a match
Min RK
@minrk
Mar 25 2015 23:02
Now you have localhost vs 127
I don't understand why you need to relax the port. Why isn't the nginx public URL suffice, as long as nginx is configured to send the proxy headers?
Jonathan Frederic
@jdfreder
Mar 25 2015 23:05
Yay! Success
Sometimes my browser autocompletes to localhost since I've been typing it in so many times today.
Awesome
@minrk I'm not sure, it may be how nginx is forwarding the socket requests
My setup is essentially the same as tmpnb-deploy 's
location ~* /(user[-/][a-zA-Z0-9]*)/(api/kernels/[^/]+/(channels|iopub|shell|stdin)|terminals/websocket)/? {
            proxy_pass http://127.0.0.1:8000;

            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header Host $host;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

            proxy_set_header X-NginX-Proxy true;

            # WebSocket support
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_read_timeout 86400;
        }
Min RK
@minrk
Mar 25 2015 23:08
@rgbkrk shouldn't origin be that of nginx?
Kyle Kelley
@rgbkrk
Mar 25 2015 23:10
need to escape the http://
http:\/\/
er wait
Min RK
@minrk
Mar 25 2015 23:11
oh, I guess it is
Kyle Kelley
@rgbkrk
Mar 25 2015 23:20
I'm wrong, don't need to escape the //
Jonathan Frederic
@jdfreder
Mar 25 2015 23:23
I'm confused, what about escaping the // @rgbkrk ? The command works as I pasted above:
jupyterhub --Spawner.cmd="['jupyterhub-singleuser', '--NotebookApp.allow_origin_pat=\'http://127\.0\.0\.1(:\d+)?\'']"