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
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