print-sequential interruptibility

25 views
Skip to first unread message

Colin Jones

unread,
Sep 21, 2012, 4:19:22 PM9/21/12
to cloju...@googlegroups.com
Currently, clojure.core/print-sequential has the potential for
problems in the face of thread interruption. When you print a large
sequence, and interrupt the thread doing the printing, the only way
I'm aware of to get it to stop printing is to call the evil
Thread.stop [1]. In REPLy, I'm currently monkey-patching some
Thread.interrupted checks into print-sequential so that I can avoid
Thread.stop when printing sequences.

Would there be interest in a patch for print-sequential that would
cause an InterruptedException to be thrown when Thread.interrupt is
called on a thread?

This would replace the current behavior of continuing to print until
the end of the sequence, with the interrupted flag set on the thread.
There's an argument to be made that the calling code should be
responsible for checking the flag. But since print-sequential is
really a loop with [potentially] lots of writes internally, my
thinking is that the loop should do its own Thread.interrupted
monitoring.

Thoughts?

- Colin


[1] http://docs.oracle.com/javase/1.4.2/docs/api/java/lang/Thread.html#stop()


--
Colin Jones
@trptcolin

Stuart Sierra

unread,
Sep 21, 2012, 4:56:34 PM9/21/12
to cloju...@googlegroups.com
I think you're right, Colin, although I don't know a whole lot about Java thread interruption.

I can say that Thread.stop is not especially evil in this case because print-sequential is (presumably) not holding any locks.

-S

Colin Jones

unread,
Sep 21, 2012, 5:11:46 PM9/21/12
to cloju...@googlegroups.com
Thanks for the feedback, Stuart. Regarding Thread.stop(), I can
imagine printing while holding a different (application-specific) lock
- or am I missing something?

I've created CLJ-1073 with a patch for this:
http://dev.clojure.org/jira/browse/CLJ-1073

- Colin
> --
> You received this message because you are subscribed to the Google Groups
> "Clojure Dev" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/clojure-dev/-/2_tGdbu5DEUJ.
> To post to this group, send email to cloju...@googlegroups.com.
> To unsubscribe from this group, send email to
> clojure-dev...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/clojure-dev?hl=en.



--
Colin Jones
@trptcolin
Reply all
Reply to author
Forward
0 new messages