Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.004 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'failing': 0.07; 'lines,': 0.07; 'don': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'python': 0.11; 'def': 0.12; 'thread': 0.14; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'such,': 0.16; 'thread?': 0.16; 'true:': 0.16; 'trying': 0.19; 'example': 0.22; 'import': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'text,': 0.24; 'values': 0.27; 'header:X-Complaints-To:1': 0.27; 'see,': 0.30; 'code': 0.31; 'lines': 0.31; 'embed': 0.31; 'os,': 0.31; 'prints': 0.31; 'another': 0.32; 'received:fr': 0.33; 'skip:# 10': 0.33; 'skip:t 40': 0.33; "i'd": 0.34; 'anybody': 0.35; 'but': 0.35; 'next': 0.36; 'hi,': 0.36; 'two': 0.37; 'to:addr:python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'how': 0.40; 'first': 0.61; 'show': 0.63; 'soon': 0.63; 'more': 0.64; 'due': 0.66; 'prompt': 0.68; 'received:109': 0.72 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Gelonida N Subject: embedding ipython kernel in a thread Date: Mon, 09 Jun 2014 14:59:42 +0200 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Gmane-NNTP-Posting-Host: 1-75-190-109.dsl.ovh.fr User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 52 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1402318812 news.xs4all.nl 2953 [2001:888:2000:d::a6]:36628 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73024 Hi, I'd like to embed an ipython kernel in an appliction, such, that I can use ipython console --existing kernel-.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()