# Copyright 2010 Alon Zakai ('kripken'). All rights reserved. # This file is part of Syntensity/the Intensity Engine, an open source project. See COPYING.txt for licensing. ''' Uses the Linux 'cpulimit' command to limit CPU usage. ''' import os, subprocess import signal # Python 2.5 killing method, see below from intensity.base import get_config from intensity.signals import shutdown max_cpu = int(get_config('CPULimiter', 'limit', '50')) process = subprocess.Popen( "exec cpulimit -p %d -l %d" % (os.getpid(), max_cpu), # exec is useful so a second process is not spawned shell=True, stdout=subprocess.PIPE, ) #process.communicate() def terminate(sender, **kwargs): os.kill(process.pid, signal.SIGKILL) process.wait() # Or, in Python 2.6: process.terminate()
# This file is part of Syntensity/the Intensity Engine, an open source project. See COPYING.txt for licensing. import random, threading from intensity.base import * from intensity.logging import * from intensity.signals import text_message, shutdown, client_connect, client_disconnect from intensity.server.persistence import Clients from intensity.base import get_config from intensity.components.irclib.ircbot import SingleServerIRCBot from intensity.components.irclib.irclib import nm_to_n, nm_to_h, irc_lower, ip_numstr_to_quad, ip_quad_to_numstr # Parameters SERVER = get_config('IRC', 'server', 'irc.freenode.net') PORT = int(get_config('IRC', 'port', '8001')) CHANNEL = get_config('IRC', 'channel', '#syntensity') NICKNAME = get_config('IRC', 'nickname', 'ServerBot') INSTANCE_NAME = get_config('IRC', 'instance_name', 'InstanceName') ## Sends a message to people connected to this Intensity Engine server def send_intensity_message(speaker, text): CModule.send_text_message(-1, '[[IRC]] %s: %s' % (speaker, text), True) class Bot(SingleServerIRCBot): def __init__(self, channel, nickname, server, port=6667): SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname) self.channel = channel
# Copyright 2010 Alon Zakai ('kripken'). All rights reserved. # This file is part of Syntensity/the Intensity Engine, an open source project. See COPYING.txt for licensing. import random, threading from intensity.base import * from intensity.logging import * from intensity.signals import text_message, shutdown, client_connect, client_disconnect from intensity.server.persistence import Clients from intensity.base import get_config from intensity.components.irclib.ircbot import SingleServerIRCBot from intensity.components.irclib.irclib import nm_to_n, nm_to_h, irc_lower, ip_numstr_to_quad, ip_quad_to_numstr # Parameters SERVER = get_config('IRC', 'server', 'irc.freenode.net') PORT = int(get_config('IRC', 'port', '8001')) CHANNEL = get_config('IRC', 'channel', '#syntensity') NICKNAME = get_config('IRC', 'nickname', 'ServerBot') INSTANCE_NAME = get_config('IRC', 'instance_name', 'InstanceName') ## Sends a message to people connected to this Intensity Engine server def send_intensity_message(speaker, text): CModule.send_text_message(-1, '[[IRC]] %s: %s' % (speaker, text), True) class Bot(SingleServerIRCBot): def __init__(self, channel, nickname, server, port=6667): SingleServerIRCBot.__init__(self, [(server, port)], nickname, nickname) self.channel = channel
# Copyright 2010 Alon Zakai ('kripken'). All rights reserved. # This file is part of Syntensity/the Intensity Engine, an open source project. See COPYING.txt for licensing. ''' Uses the Linux 'cpulimit' command to limit CPU usage. ''' import os, subprocess import signal # Python 2.5 killing method, see below from intensity.base import get_config from intensity.signals import shutdown max_cpu = int( get_config('CPULimiter', 'limit', '50') ) process = subprocess.Popen( "exec cpulimit -p %d -l %d" % (os.getpid(), max_cpu), # exec is useful so a second process is not spawned shell=True, stdout=subprocess.PIPE, ) #process.communicate() def terminate(sender, **kwargs): os.kill(process.pid, signal.SIGKILL) process.wait() # Or, in Python 2.6: process.terminate() shutdown.connect(terminate, weak=False)