Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.mixmin.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.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.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'cache': 0.07; 'failing': 0.07; 'lines,': 0.07; 'don': 0.09; 'exit': 0.09; 'skip:$ 20': 0.09; 'skip:$ 30': 0.09; 'skip:$ 40': 0.09; 'received:localdomain': 0.11; 'python': 0.11; 'def': 0.12; 'thread': 0.14; 'skip:$ 50': 0.16; 'skip:/ 60': 0.16; 'skip:f 80': 0.16; 'skip:u 50': 0.16; 'such,': 0.16; 'thread?': 0.16; 'true:': 0.16; 'attach': 0.16; 'skip:= 10': 0.16; 'filename:fname piece:txt': 0.16; 'wrote:': 0.18; 'trying': 0.19; 'example': 0.22; 'import': 0.22; 'shell': 0.22; 'header:User-Agent:1': 0.23; 'certainly': 0.24; 'skip:i 40': 0.24; 'text,': 0.24; 'script': 0.25; 'skip:" 30': 0.26; 'skip:" 20': 0.27; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'see,': 0.30; 'skip:( 20': 0.30; 'code': 0.31; 'lines': 0.31; 'break;': 0.31; 'embed': 0.31; 'os,': 0.31; 'prints': 0.31; 'skip:= 20': 0.31; 'another': 0.32; 'skip:# 10': 0.33; 'skip:t 40': 0.33; "i'd": 0.34; 'skip:u 20': 0.35; 'anybody': 0.35; 'but': 0.35; 'add': 0.35; 'skip:> 10': 0.36; 'skip:f 40': 0.36; 'next': 0.36; 'hi,': 0.36; 'two': 0.37; 'received:76': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'skip:u 10': 0.60; 'skip:i 50': 0.60; 'new': 0.61; "you're": 0.61; 'first': 0.61; 'show': 0.63; 'soon': 0.63; 'provide': 0.64; 'more': 0.64; 'skip:f 50': 0.65; 'due': 0.66; 'header:Reply-To:1': 0.67; 'prompt': 0.68; 'reply-to:no real name:2**0': 0.71; 'url:v': 0.71; 'url:youtube': 0.71; 'url:watch': 0.77; 'skip:$ 10': 0.81; 'gelonida': 0.84; 'carlos': 0.91 Date: Mon, 09 Jun 2014 14:34:56 +0100 From: Carlos Anselmo Dias User-Agent: Mozilla/5.0 (X11; Linux i686; rv:24.0) Gecko/20100101 Thunderbird/24.5.0 MIME-Version: 1.0 To: python-list@python.org Subject: Re: embedding ipython kernel in a thread References: In-Reply-To: Content-Type: multipart/mixed; boundary="------------040004000502090606040904" X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: carlos@premium-sponsor.com 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: 188 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1402320905 news.xs4all.nl 2831 [2001:888:2000:d::a6]:43509 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73026 This is a multi-part message in MIME format. --------------040004000502090606040904 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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-.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 --------------040004000502090606040904 Content-Type: text/plain; charset=UTF-8; name="script.txt" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="script.txt" $id_flux["idsponsor"]=2; // $flux_treat=array(397,382,769,770); //$flux_treat=array(397,382); $flux_treat=array(521,6876); $textemailmessage=""; include("../../conf.inc.php"); if(is_array($flux_treat)){ foreach($flux_treat as $kfluxtotreat => $vfluxtotreat){ //echo $kfluxtreatsubtype."
"; if(!empty($array_language_flux_default[$vfluxtotreat])){ $id_language_default=$array_language_flux_default[$vfluxtotreat]; } $info_page_records=explode("|",$array_number_records_per_page_start_flux[$vfluxtotreat]); if(is_array($id_flux["detail"][$vfluxtotreat])){ foreach($id_flux["detail"][$vfluxtotreat]["Sponsor"]["url"]["information"]["xml"] as $kfluxtreatsubtype=>$vfluxtreatsubtype){ //control if execution is allowed by kfluxtreatsubtype and add exit echo $kfluxtreatsubtype."
"; if(check_lock_control_($kfluxtreatsubtype,"start")=="ok"){ $_ids_types_xml_cache_=$_ids_types_xml_[$kfluxtreatsubtype]; $_time_of_cache_flux_subtype=$_ids_types_xml_time_cache_[$kfluxtreatsubtype]; //echo "time of cache ".$_time_of_cache_flux_subtype."
"; if($kfluxtreatsubtype =="xml-movies"){ $number_records_or_end_position=$info_page_records[0]; $counterfilter=0; foreach($id_flux["detail"][$vfluxtotreat]["languages"] as $klg => $vlg){ foreach($ids_cats_sponsor[$vfluxtotreat] as $kcat => $vcat){ $cat_convereted_cache=$vcat; $pagenumb=$limitepaginas=$info_page_records[1]; while ($pagenumb<=$limitepaginas){ $replacements=array($id_flux["idsponsorfk"],$id_flux["loginsponsor"],$id_flux["passwordsponsor"],$kcat,"{idcatsonsponsor}",$pagenumb,$vlg,$number_records_or_end_position,"{filter}",$_SERVER['REMOTE_ADDR'],$id_flux["keysponsor"],"{tracker}","{iditemdetail}","{idsubitemdetail}","{subtracker}"); $urlstringtreat =str_replace($patterns, $replacements, $vfluxtreatsubtype); $page_number_cache=$pagenumb; echo "".$urlstringtreat."
"; $myXML = open_xml_parsing($generatecache="yes",$urlstringtreat,$id_flux["idsponsor"],$vfluxtotreat,$_ids_types_xml_cache_,$klg,$_id_filter_="x",$cat_convereted_cache,$_id_product_sub_type_="x",$_time_of_cache_flux_subtype,"yes|5;3|".$page_number_cache); if(substr($myXML,0,8)=="ERRORMSG"){ $textemailmessage.=$myXML; }else{ $xml = new CXml(); $xml->Set_XML_data($myXML); $global1_[$video->id]['str_informations_db'] = prepare_strings_database(remove_weird_symbols_caracteres(treatment_string_tags($_complete_str_="",$_tag_to_treat_="",$str_array_str_informations_db),$vfluxtotreat)); unset($str_array_str_informations_db,$str_array_images); $myMovie=movies_management($global1_); if(substr($myMovie,0,8)=="ERRORMSG"){ $textemailmessage.=$myMovie; unset($global1_[$video->id]); }else{ unset($global1_[$video->id]); } }//if(!is_array($global1_[$video->id])){ }//foreach($xml->obj_data->videos_site[0]->videos[0]->video as $video){ }//if(isset($xml->obj_data->videos_site[0]->videos[0])){ }//else if(substr($myXML,0,8)=="ERRORMSG"){ $pagenumb++; $limitepaginas=$xml->obj_data->videos_site[0]->navigation[0]->nb_pages[0]; unset($myXML); if($pagenumb >$limitepaginas){ break; } }//while ($pagenumb<=$limitepaginas){ //echo $array_modules_to_include_subtype[$kfluxtreatsubtype]."
"; //@include($array_modules_to_include_subtype[$kfluxtreatsubtype]); /* if($vfluxtotreat==382 || $vfluxtotreat==397){ $myMovie=movies_management($global1_); if(substr($myMovie,0,8)=="ERRORMSG"){ $textemailmessage.=$myMovie; echo $textemailmessage."
"; } unset($global1_); } */ }//foreach($ids_cats as $kcat => $vcat){ /* if($vfluxtotreat==382 || $vfluxtotreat==397){ $myMovie=movies_management($global1_); if(substr($myMovie,0,8)=="ERRORMSG"){ $textemailmessage.=$myMovie; echo $textemailmessage."
"; } unset($global1_); } */ $counterfilter++; }//foreach($id_flux["detail"][$k]["languages"] as $klg => $vlg){ } }//if(check_lock_control_($kfluxtreatsubtype)==""){ check_lock_control_($kfluxtreatsubtype,"end"); }//foreach($id_flux["detail"][$vfluxtotreat]["Sponsor"]["url"]["information"]["xml"] as $kfluxtreatsubtype=>$vfluxtreatsubtype){ }//if(is_array($id_flux["detail"])){ } } --------------040004000502090606040904--