* Jumping back to REPL prompt on ^C
@ 2010-06-20 23:15 Taylor Venable
2010-07-04 20:52 ` Neil Jerram
0 siblings, 1 reply; 5+ messages in thread
From: Taylor Venable @ 2010-06-20 23:15 UTC (permalink / raw)
To: guile-user
Hi there, I'm writing a piece of code with a web server component, and
part of that being that I want to jump back to the REPL when one hits
^C. So it would go something like this:
scheme@(guile-user)> (start-server)
;;; handling requests
^C
scheme@(guile-user)>
What I tried doing was essentially this:
(call/cc (lambda (k) (sigaction SIGINT (lambda (_) (k))) (start-server)))
Except *sometimes* when I hit ^C I ended up with an error that stops
the guile program completely, seemingly due to the readline library
that I've enabled in the REPL. When I simplify my test I'm able to
get the same fatal error all the time.
scheme@(guile-user)> (call/cc (lambda (k) (sigaction SIGINT (lambda (_) (k)))))
(#<procedure 1e04720 at ice-9/boot-9.scm:3422:34 (sig)> . 67108864)
scheme@(guile-user)> Backtrace:
In ice-9/boot-9.scm:
170: 12 [catch #t #<catch-closure 1ad8900> ...]
In unknown file:
?: 11 [catch-closure]
In ice-9/boot-9.scm:
62: 10 [call-with-prompt prompt0 ...]
3437: 9 [top-repl]
In system/repl/repl.scm:
105: 8 [start-repl scheme #:level 0 #:welcome #t]
110: 7 [next-char #f]
In unknown file:
?: 6 [peek-char #<undefined>]
In ice-9/buffered-input.scm:
72: 5 [get-character]
107: 4 [#<procedure 1ee1100 at ice-9/buffered-input.scm:105:28
(continuation?)> #f]
In ice-9/eval.scm:
374: 3 [eval # #]
In unknown file:
?: 2 [%readline "" #<input: standard input /dev/pts/2> ...]
In ice-9/boot-9.scm:
115: 1 [#<procedure 1c4eca8 at ice-9/boot-9.scm:109:6 (thrown-k .
args)> misc-error ...]
In unknown file:
?: 0 [catch-closure misc-error "%readline" "readline is not reentrant" () #f]
ERROR: In procedure %readline:
ERROR: readline is not reentrant
After the error my terminal is left without key echoing enabled. Is
there a way to accomplish what I'm trying to do? Perhaps I simply
cannot do this with readline support enabled? I'm not quite skilled
enough to figure out if my method is even a sensible way to try to get
it, or maybe I've violated something important by trying to invoke the
current continuation at the REPL. I'm using Guile 2.0 from git,
commit 8d10ccae79ff46f0ebea92ba36acfaebafba8d86 on Linux x86_64.
Thanks for any ideas or explanation,
--
Taylor C. Venable
http://metasyntax.net/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Jumping back to REPL prompt on ^C
2010-06-20 23:15 Jumping back to REPL prompt on ^C Taylor Venable
@ 2010-07-04 20:52 ` Neil Jerram
2010-07-08 19:31 ` Andy Wingo
0 siblings, 1 reply; 5+ messages in thread
From: Neil Jerram @ 2010-07-04 20:52 UTC (permalink / raw)
To: Taylor Venable; +Cc: guile-user
Taylor Venable <taylor@metasyntax.net> writes:
> Hi there, I'm writing a piece of code with a web server component, and
> part of that being that I want to jump back to the REPL when one hits
> ^C. So it would go something like this:
>
> scheme@(guile-user)> (start-server)
> ;;; handling requests
> ^C
> scheme@(guile-user)>
>
> What I tried doing was essentially this:
>
> (call/cc (lambda (k) (sigaction SIGINT (lambda (_) (k))) (start-server)))
Just a couple of notes here.
First, continuations usually take an argument: the value which will be
the return value of the (call/cc ...) expression. So '(k)' may be
wrong.
Second, I wonder if you meant (lambda _ ...) instead of (lambda (_)
...). I often use the former when I want a lambda that accepts any
number of arguments.
> Except *sometimes* when I hit ^C I ended up with an error that stops
> the guile program completely, seemingly due to the readline library
> that I've enabled in the REPL. When I simplify my test I'm able to
> get the same fatal error all the time.
[..]
> In unknown file:
> ?: 0 [catch-closure misc-error "%readline" "readline is not reentrant" () #f]
This suggests to me that the code was already inside readline when you
hit ^C.
Does (start-server) ever return naturally? If it does, there's a window
where it's just returned and the REPL is calling readline to read the
next line of input, but the terminal may not have shown the prompt yet.
So if you type ^C in that window, the error above would be expected.
Alternatively, does the code inside (start-server) ever use readline?
Perhaps by mistake it is using '(readline)' instead of '(read-line)'
from (ice-9 rdelim)? In this case there'd obviously be loads more
chances of seeing the above error.
Regards,
Neil
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Jumping back to REPL prompt on ^C
2010-07-04 20:52 ` Neil Jerram
@ 2010-07-08 19:31 ` Andy Wingo
2010-07-09 15:57 ` Andy Wingo
0 siblings, 1 reply; 5+ messages in thread
From: Andy Wingo @ 2010-07-08 19:31 UTC (permalink / raw)
To: Neil Jerram; +Cc: guile-user
Hi Neil & Taylor,
On Sun 04 Jul 2010 21:52, Neil Jerram <neil@ossau.uklinux.net> writes:
> Taylor Venable <taylor@metasyntax.net> writes:
>
>> Hi there, I'm writing a piece of code with a web server component, and
>> part of that being that I want to jump back to the REPL when one hits
>> ^C. So it would go something like this:
>>
>> scheme@(guile-user)> (start-server)
>> ;;; handling requests
>> ^C
>> scheme@(guile-user)>
>>
>> What I tried doing was essentially this:
>>
>> (call/cc (lambda (k) (sigaction SIGINT (lambda (_) (k))) (start-server)))
>
> Just a couple of notes here.
>
> First, continuations usually take an argument: the value which will be
> the return value of the (call/cc ...) expression. So '(k)' may be
> wrong.
Indeed, though the intention may be that an escape returns 0 values;
unlikely however.
> Second, I wonder if you meant (lambda _ ...) instead of (lambda (_)
> ...). I often use the former when I want a lambda that accepts any
> number of arguments.
True, though sigaction handlers do get called with only one argument.
>> Except *sometimes* when I hit ^C I ended up with an error that stops
>> the guile program completely, seemingly due to the readline library
>> that I've enabled in the REPL. When I simplify my test I'm able to
>> get the same fatal error all the time.
> [..]
>> In unknown file:
>> ?: 0 [catch-closure misc-error "%readline" "readline is not reentrant" () #f]
You know, I've seen this on a couple occaisions. If you can find out how
to reproduce this I would be very interested.
In the future you should be able to just return to the prompt on SIGINT
by setting a REPL option. Dunno if that works for Taylor, though...
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Jumping back to REPL prompt on ^C
2010-07-08 19:31 ` Andy Wingo
@ 2010-07-09 15:57 ` Andy Wingo
2010-07-27 21:16 ` Taylor Venable
0 siblings, 1 reply; 5+ messages in thread
From: Andy Wingo @ 2010-07-09 15:57 UTC (permalink / raw)
To: guile-user
On Thu 08 Jul 2010 21:31, Andy Wingo <wingo@pobox.com> writes:
>>> Except *sometimes* when I hit ^C I ended up with an error that stops
>>> the guile program completely, seemingly due to the readline library
>>> that I've enabled in the REPL. When I simplify my test I'm able to
>>> get the same fatal error all the time.
>> [..]
>>> In unknown file:
>>> ?: 0 [catch-closure misc-error "%readline" "readline is not reentrant" () #f]
>
> You know, I've seen this on a couple occaisions. If you can find out how
> to reproduce this I would be very interested.
I believe I have quashed all of these. Let me know if you can still
reproduce this with git.
Andy
--
http://wingolog.org/
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Jumping back to REPL prompt on ^C
2010-07-09 15:57 ` Andy Wingo
@ 2010-07-27 21:16 ` Taylor Venable
0 siblings, 0 replies; 5+ messages in thread
From: Taylor Venable @ 2010-07-27 21:16 UTC (permalink / raw)
To: Andy Wingo; +Cc: guile-user
Hi Andy. Very sorry for the late reply, it's been a few weeks since I
caught up with the list.
On Fri, Jul 9, 2010 at 11:57 AM, Andy Wingo <wingo@pobox.com> wrote:
> On Thu 08 Jul 2010 21:31, Andy Wingo <wingo@pobox.com> writes:
>
>>>> Except *sometimes* when I hit ^C I ended up with an error that stops
>>>> the guile program completely, seemingly due to the readline library
>>>> that I've enabled in the REPL. When I simplify my test I'm able to
>>>> get the same fatal error all the time.
>>> [..]
>>>> In unknown file:
>>>> ?: 0 [catch-closure misc-error "%readline" "readline is not reentrant" () #f]
>>
>> You know, I've seen this on a couple occaisions. If you can find out how
>> to reproduce this I would be very interested.
>
> I believe I have quashed all of these. Let me know if you can still
> reproduce this with git.
I just rebuilt with the latest git and it seems to be working. I've
been using this as a test:
(call/cc (lambda (k) (sigaction SIGINT (lambda (_) (k))) (let loop () (loop))))
And then interrupting with ^C. I also tried using SIGQUIT and ^\ with
the same successful effect, so it looks like it works.
Many thanks!
--
Taylor C. Venable
http://metasyntax.net/
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-07-27 21:16 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-06-20 23:15 Jumping back to REPL prompt on ^C Taylor Venable
2010-07-04 20:52 ` Neil Jerram
2010-07-08 19:31 ` Andy Wingo
2010-07-09 15:57 ` Andy Wingo
2010-07-27 21:16 ` Taylor Venable
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).