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

  • Home
  • SEARCH
  • 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 8807973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:30:09+00:00 2026-06-14T02:30:09+00:00

I have this code: … …. ping_thread = Thread.new { loop do sleep 2

  • 0

I have this code:

…
….

    ping_thread = Thread.new {
        loop do
            sleep 2
            ping
        end
    }
    ping_thread.join

    puts "TEST"

…
….

it executes the ping function but does not move on printing the “TEST” statement. The ping function has a simple “puts “PING”” statement inside of it. I want the ping_thread to run as a background thread.

  • 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-06-14T02:30:10+00:00Added an answer on June 14, 2026 at 2:30 am

    Thread.new will start your thread running in the background automatically, and Thread#join will block until that thread finishes its job. So normally, joining the thread is the last thing you do, when the main execution thread is done doing its work.

    Try the following code and see if it does what you want:

    ping_thread = Thread.new {
        loop do
            sleep 2
            puts "ping"
        end
    }
    
    puts "TEST"
    
    ping_thread.join
    

    Note that if you don’t join the thead in the end, it will die when the main execution thread completes its work, so that join is necessary.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code : void Main() { System.Timers.Timer t = new System.Timers.Timer (1000);
I have this code: con.Open(); cmd = new MySqlCommand(String.Format(SELECT concat(name,'|',lastname) FROM {0} WHERE ID=
I have this code: class LFSeq: # lazy infinite sequence with new elements from
I have this code : IList<MyObject> myObjects = new List<MyObject>(); if (param != null)
I have this code fragment var combo = new dhtmlXCombo(combo_zone4, alfa4, 230); combo.loadXML(create_store2.php); combo.attachEvent(onChange,
I have this code import com.crystaldecisions.reports.sdk.ReportClientDocument; ... ReportClientDocument rpt = new ReportClientDocument(); rpt.open(reportPath+fileName, 0);
I have this code: IList<Foo1> ou = session.CreateQuery(from Foo1 as f1 JOIN FETCH f1.foo2
I have this code that loads 5 images and puts them into the frame
I have this code which is in the middle of a loop: $('input[name=field_add_more]').trigger('mousedown'); mycustomfunction();
have this code import threading def Thread(f): def decorator(*args,**kargs): print(args) thread = threading.Thread(target=f, args=args)

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.