not terminatinga process

K

Kurt M. Dresner

Hi,

I'm currently programming a chat bot. The problem is that when I run
the bot, it spawns a thread that handles the incoming messages.
However, if the main thread terminates, this spawned thread terminates
too. So right now I have a busy waiting loop in my main thread, and it
uses up all my CPU time. This is not a permanent solution. What is a
good solution to this problem (such that I can kill the processes when I
want to)?

It currently kills everything by terminating the first process, and then
the instance of the robot gets falls out of scope and dies.

-Kurt

Here is the code of the main program that creates the object:

#! /usr/bin/env ruby

require 'bot'

thebot = ChaosBot.new("username","password","defaultchatname")

while thebot.connected? do
# busy wait
end
 
B

Brian Candler

I'm currently programming a chat bot. The problem is that when I run
the bot, it spawns a thread that handles the incoming messages.
However, if the main thread terminates, this spawned thread terminates
too. So right now I have a busy waiting loop in my main thread, and it
uses up all my CPU time. This is not a permanent solution. What is a
good solution to this problem (such that I can kill the processes when I
want to)?

t = Thread.new do
.. stuff in a thread
end
t.join # <<-- that's what you need

Regards,

Brian.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top