Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7419587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T08:05:49+00:00 2026-05-29T08:05:49+00:00

SOLUTION: In .irbc file, put: IRB.conf[:USE_READLINE] = false I am running some ruby code:

  • 0

SOLUTION: In .irbc file, put: IRB.conf[:USE_READLINE] = false

I am running some ruby code:

Thread.new do
 loop do
   a = @queue.pop
   puts "1"
   puts "2"
 end
end

When i run this in irb, and queue pops, it print “1”, but doesn’t print “2” right away. I have to press enter couple of times before it spits out “2”. Why is that?

Here’s my irb log:

>> Thread.new do
?>  loop do
?>    a = @queue.pop
>>    puts "1"
>>    puts "2"
>>  end
>> end
=> #<Thread:0x10ae6d1a0 sleep>
>> @queue << "something random"
1=> #<Queue:0x10aed6420>
>> 
?> 

?> 
?> 
2?> 

Here’s what I get:

>> require "thread"
=> true
>> 
?> @queue = Queue.new
=> #<Queue:0x101bc9a60>
>> 
?> Thread.new do
?>  loop do
?>    a = @queue.pop
>>    puts "1 was printed at #{Time.now.to_f}"
>>    puts "2 was printed at #{Time.now.to_f}"
>>  end
>> end
=> #<Thread:0x101bb8058 sleep>
>> 
?> @queue << 42
1 was printed at 1328144684.33667=> #<Queue:0x101bc9a60>
>> 
?> 

?> 
?> 
2 was printed at 1328144686.4642?> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T08:05:50+00:00Added an answer on May 29, 2026 at 8:05 am

    I experimented some and found out what is happening. As you might know, two Ruby threads cannot run at the same time; they just switch back and forth quickly.* Normally, if you call gets, the calling thread will wait for input, and other threads will continue (because gets releases the GIL ). However, in irb, (at least on Mac OS X) other threads do not continue to execute while it is waiting for input. Example:

    >> i = 0
    => 0
    >> Thread.new { loop { i += 1 } }
    => #<Thread:0x1094d6d68 run>
    >> i
    => 234866
    >> i
    => 401271
    

    If the thread were executing, i would be in the millions. (Tested outside irb.) Plus, ruby was using < 1% CPU.

    In your example, each time you press enter, the thread gets a split second to execute–enough time to write out a number or a newline. Then ruby switches back to irb’s thread, which writes the prompt and waits on input.

    * With JRuby, IronRuby, and Rubinius 2.0, multiple threads can run at the same time.

    Edit: I tested on Windows, and threads keep running there. If you want threads to keep running on Mac, you could save this as, say, sirb.rb (simple irb) and use it instead of irb:

    $stdout.sync = true
    while true
        print "> "
        p(eval gets)
    end
    

    Note that, unlike irb, it doesn’t support a statement spanning multiple lines, nor does it support moving the caret to edit or pressing Up for history (on Mac OS X). Example:

    > for i in 1..10; print i ** 2, " "; end; puts
    1 4 9 16 25 36 49 64 81 100 
    nil
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

--Solution found-- The correct PHP code is a combination of the two answers provided
SOLUTION FOUND: See comment Building a new rails 3.1 app. Started with a basic
MS solution for source code control is visual source safe before. Now MS advocate
SOLUTION Refer to my answer below: issues with form/iframe based file upload in Opera
Solution I did some googling and found this forum post , and here is
Solution note, not a question. I used this code to set background as a
Solution found, see my comment below D5, odbc to mysql database This code: with
SOLUTION The solution was to add the following to the top of production.rb: $:.unshift(File.expand_path('./lib',
Solution setup: DAL (class library) BLL (class library) Common (class library (some common functionality
Some solution could probably be applicable to Windows, however I am not familiar with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.