Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #73026 > unrolled thread

Re: embedding ipython kernel in a thread

Started byCarlos Anselmo Dias <carlos@premium-sponsor.com>
First post2014-06-09 14:34 +0100
Last post2014-06-09 14:34 +0100
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: embedding ipython kernel in a thread Carlos Anselmo Dias <carlos@premium-sponsor.com> - 2014-06-09 14:34 +0100

#73026 — Re: embedding ipython kernel in a thread

FromCarlos Anselmo Dias <carlos@premium-sponsor.com>
Date2014-06-09 14:34 +0100
SubjectRe: embedding ipython kernel in a thread
Message-ID<mailman.10911.1402320905.18130.python-list@python.org>

[Multipart message — attachments visible in raw view] — view raw

On 06/09/2014 01:59 PM, Gelonida N wrote:
> Hi,
>
> I'd like to embed an ipython kernel in an appliction, such, that I can 
> use
>
> ipython console --existing kernel-<pid>.json lateron to connect to it 
> and to look at some values
>
>
> Due to various reason I don not want to start it in the main thread.
>
> If you look at following example you will see, that I can start an 
> ipython kernel and
> connect to it as long as I start it in the main thread.
>
> as soon as I start the kernel in another thread my ipython client 
> prints  the first few lines and a welcome text, but
> no prompt is shown.
>
> Does anybody know a way o how to start IPython outside of the main 
> thread?
>
>
> Below code trying to show a working setup with ipython kernel in the 
> main thread and failing if ipython kernel is started from another thread
>
> #!/usr/bin/env python
> import os, time, threading
> from IPython import embed_kernel
>
> cnt  = { 'value' : 0 }
> def run_ip_kernel():
>     embed_kernel(local_ns={ 'cnt': cnt})
>
> def example_thread():
>     while True:
>         cnt['value'] += 1
>         print(cnt['value'])
>         time.sleep(5)
>
> main_thread = run_ip_kernel
> other_thread = example_thread
>
> # if I uncomment the next two lines, then I can no more
> # execute my interactive IPython shell
> #main_thread = example_thread
> #other_thread = run_ip_kernel
>
> print("now you can try to connect to this shell with:")
> print("ipython console --existing kernel-%d.json" % os.getpid())
> threading.Thread(target=other_thread).start()
> main_thread()
>
>

Whatever you're trying to do(...) ... if you look at the script I 
provide you in attach and if you can think how usefull it would be to 
control exponencially what you need ... that's certainly one best 
approach ...

https://www.youtube.com/watch?v=p7CaiWxKYBo

Regards,
Carlos

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web