« Return to Thread: Run Io coroutines in background simultaneous to using Io> prompt in foreground?

Re: Run Io coroutines in background simultaneous to using Io> prompt in foreground?

by Rich Collins :: Rate this Message:

Reply to Author | View in Thread

If it is blocking it will block the entire thread (and that IoState).  
You will probably have to use non-blocking I/O or communicate between  
the threads using one of the techniques you mentioned.

There is a DistributedObjects addon that might help.  Perhaps Steve  
can give you more detail.

On Jun 9, 2009, at 10:09 PM, dennisf486 wrote:

>
>
> Thanks that was a big help but it wasn't quite the solution. I was  
> able to make it run a background process simultaneous to generating  
> my own prompt. But that only solves half my problem: "EditLine  
> readLine" is a blocking call, so it still halts other coroutines  
> while waiting at the "fake Io>" prompt. (Because you can't yield  
> between keypresses.) So it still only executes the background loops  
> once per every time I hit the "return" key on a command in the prompt.
>
> I'm thinking maybe I need something like:
>
> createThread("loop that does readLine for FakeIo> prompt")
> @@backgroundCoroutine("do stuff in a loop that yields at the end")
>
> loop(
> check for new command from other thread
> yield if no new command
> doString() if there is a command
> )
>
> But how do I get the string data out of the separate VM on the  
> thread that's displaying the FakeIo> prompt and into the original VM  
> that has the backgroundCoroutines and the doString loop? Shared  
> memory? Pipes? Send it to localhost via TCP/IP through a BSD socket??
>
> For the sake of completeness, here's the test code I've got so far:  
> (The idea is the background coroutine increments n every second,  
> while the foreground prompt can change or print n if you type the  
> right command. The fact that the background coroutine picks up on  
> the change and begins incrementing the new value of n proves the  
> foreground prompt changed a variable in the background coroutine.)
>
> n := 1
>
> doBackground := method(
> loop("N is " print; n println; n = n + 1; wait(1))
> )
>
> doPrompt := method(
> s := ""; loop(println; s = EditLine readLine("FakeIo>");  
> doString(s); yield)
> )
>
> @@doBackground
> doPrompt
>
> --- In iolanguage@..., Steve Dekorte <steve@...> wrote:
> >
> >
> > On 2009-06-07, at 9:18 PM, dennisf486 wrote:
> > > With the prompt presented by the Io executable, if I type  
> something
> > > the prompt goes away until it is done, even if I type something  
> like
> > > "o1 @test" to launch a coroutine. Is this a fundamental limitation
> > > of Io (can't enter new commands while coroutines are running)? I
> > > can think of several approaches; which, if any, are right?
> >
> > The code that presents the user with the prompt and receives the  
> input
> > line can just call doString(theInputString) and I think it should  
> have
> > the behavior you are looking for.
> >
>
>
>
> <!-- #ygrp-mkp{ border: 1px solid #d8d8d8; font-family: Arial;  
> margin: 14px 0px; padding: 0px 14px; } #ygrp-mkp hr{ border: 1px  
> solid #d8d8d8; } #ygrp-mkp #hd{ color: #628c2a; font-size: 85%; font-
> weight: bold; line-height: 122%; margin: 10px 0px; } #ygrp-mkp  
> #ads{ margin-bottom: 10px; } #ygrp-mkp .ad{ padding: 0 0; } #ygrp-
> mkp .ad a{ color: #0000ff; text-decoration: none; } --> <!-- #ygrp-
> sponsor #ygrp-lc{ font-family: Arial; } #ygrp-sponsor #ygrp-lc  
> #hd{ margin: 10px 0px; font-weight: bold; font-size: 78%; line-
> height: 122%; } #ygrp-sponsor #ygrp-lc .ad{ margin-bottom: 10px;  
> padding: 0 0; } --> <!-- #ygrp-mlmsg {font-size:13px; font-family:  
> arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small;}  
> #ygrp-mlmsg table {font-size:inherit;font:100%;} #ygrp-mlmsg select,  
> input, textarea {font:99% arial,helvetica,clean,sans-serif;} #ygrp-
> mlmsg pre, code {font:115% monospace;*font-size:100%;} #ygrp-mlmsg *  
> {line-height:1.22em;} #ygrp-text{ font-family: Georgia; } #ygrp-
> text p{ margin: 0 0 1em 0; } dd.last p a { font-family: Verdana;  
> font-weight: bold; } #ygrp-vitnav{ padding-top: 10px; font-family:  
> Verdana; font-size: 77%; margin: 0; } #ygrp-vitnav a{ padding: 0  
> 1px; } #ygrp-mlmsg #logo{ padding-bottom: 10px; } #ygrp-reco  
> { margin-bottom: 20px; padding: 0px; } #ygrp-reco #reco-head { font-
> weight: bold; color: #ff7900; } #reco-category{ font-size: 77%; }  
> #reco-desc{ font-size: 77%; } #ygrp-vital a{ text-decoration:  
> none; } #ygrp-vital a:hover{ text-decoration: underline; } #ygrp-
> sponsor #ov ul{ padding: 0 0 0 8px; margin: 0; } #ygrp-sponsor #ov  
> li{ list-style-type: square; padding: 6px 0; font-size: 77%; } #ygrp-
> sponsor #ov li a{ text-decoration: none; font-size: 130%; } #ygrp-
> sponsor #nc{ background-color: #eee; margin-bottom: 20px; padding: 0  
> 8px; } #ygrp-sponsor .ad{ padding: 8px 0; } #ygrp-sponsor .ad  
> #hd1{ font-family: Arial; font-weight: bold; color: #628c2a; font-
> size: 100%; line-height: 122%; } #ygrp-sponsor .ad a{ text-
> decoration: none; } #ygrp-sponsor .ad a:hover{ text-decoration:  
> underline; } #ygrp-sponsor .ad p{ margin: 0; font-weight: normal;  
> color: #000000; } o{font-size: 0; } .MsoNormal{ margin: 0 0 0 0; }  
> #ygrp-text tt{ font-size: 120%; } blockquote{margin: 0 0 0  
> 4px;} .replbq{margin:4} dd.last p span { margin-right: 10px; font-
> family: Verdana; font-weight: bold; } dd.last p span.yshortcuts  
> { margin-right: 0; } div.photo-title a, div.photo-title a:active,  
> div.photo-title a:hover, div.photo-title a:visited { text-
> decoration: none; } div.file-title a, div.file-title a:active,  
> div.file-title a:hover, div.file-title a:visited { text-decoration:  
> none; } #ygrp-msg p#attach-count { clear: both; padding: 15px 0 3px  
> 0; overflow: hidden; } #ygrp-msg p#attach-count span { color:  
> #1E66AE; font-weight: bold; } div#ygrp-mlmsg #ygrp-msg p a  
> span.yshortcuts { font-family: Verdana; font-size: 10px; font-
> weight: normal; } #ygrp-msg p a { font-family: Verdana; font-size:  
> 10px; } #ygrp-mlmsg a { color: #1E66AE; } div.attach-table div div a  
> { text-decoration: none; } div.attach-table { width: 400px; } -->

 « Return to Thread: Run Io coroutines in background simultaneous to using Io> prompt in foreground?