示例#1
0
    def kickstart(self):
        curr_proc_counter = self.proc_counter
        self.proc_counter += 1

        try:
            shutdown.disconnect(self.proc.dispatch_uid)
        except:
            pass
        try:
            self.proc.terminate()
        except:
            pass
        self.proc = Process(target=self.component_main,
                            args=(self.to_component, self.from_component))
        self.proc.daemon = True
        self.proc.start()

        # Daemon flag seems not to work, so do this
        curr_proc = self.proc
        curr_proc.dispatch_uid = curr_proc_counter

        def terminate_proc(sender, **kwargs):
            if curr_proc.is_alive():
                try:
                    if WINDOWS:
                        curr_proc.terminate()
                    else:
                        os.kill(curr_proc.pid,
                                signal.SIGKILL)  # Stronger method
                except:
                    pass

        shutdown.connect(terminate_proc,
                         weak=False,
                         dispatch_uid=curr_proc_counter)
示例#2
0
    def kickstart(self):
        curr_proc_counter = self.proc_counter
        self.proc_counter += 1

        try:
            shutdown.disconnect(self.proc.dispatch_uid)
        except:
            pass
        try:
            self.proc.terminate()
        except:
            pass
        self.proc = Process(target=self.component_main, args=(self.to_component, self.from_component))
        self.proc.daemon = True
        self.proc.start()

        # Daemon flag seems not to work, so do this
        curr_proc = self.proc
        curr_proc.dispatch_uid = curr_proc_counter
        def terminate_proc(sender, **kwargs):
            if curr_proc.is_alive():
                try:
                    if WINDOWS:
                        curr_proc.terminate()
                    else:
                        os.kill(curr_proc.pid, signal.SIGKILL) # Stronger method
                except:
                    pass

        shutdown.connect(terminate_proc, weak=False, dispatch_uid=curr_proc_counter)
示例#3
0
                        )  # Will fail on Windows, so must have 2.6 there!
            Module.server_proc.wait()
        except OSError:
            log(logging.ERROR, "Stopping server process failed.")
        # Or, in Python 2.6:   process.terminate()
        Module.server_proc = None

        def do_disconnect():
            CModule.disconnect()

        main_actionqueue.add_action(do_disconnect)


# Note strictly necessary, as the server will shut down if idle - but why not
# shut it down when the client shuts down.
shutdown.connect(stop_server, weak=False)


def show_gui(sender, **kwargs):
    if has_server():
        if check_server_ready():
            CModule.run_cubescript('''
                guitext "Local server: Running"
                guistayopen [
                    guibutton "  stop" [ (run_python "intensity.components.server_runner.stop_server()") ]
                ]
                guibutton "  show output" [ showgui local_server_output ]
                guistayopen [
                    guibutton "  save map" [ do_upload ]
                ]
                guibutton "  restart map" "showgui restart_map"
示例#4
0
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)
示例#5
0
                Module.server_proc.terminate()
            else:
                os.kill(Module.server_proc.pid, signal.SIGKILL) # Will fail on Windows, so must have 2.6 there!
            Module.server_proc.wait()
        except OSError:
            log(logging.ERROR, "Stopping server process failed.");
        # Or, in Python 2.6:   process.terminate()
        Module.server_proc = None

        def do_disconnect():
            CModule.disconnect()
        main_actionqueue.add_action(do_disconnect)

# Note strictly necessary, as the server will shut down if idle - but why not
# shut it down when the client shuts down.
shutdown.connect(stop_server, weak=False)

def show_gui(sender, **kwargs):
    if has_server():
        if check_server_ready():
            CModule.run_script('''
                GUI.text("Local server: Running")
                GUI.stayOpen([[ GUI.button("  stop", [=[ Engine.startStopLocalServer() ]=]) ]])
                GUI.button("  show output", [[ GUI.show("local_server_output") ]])
                GUI.stayOpen([[ GUI.button("  save map", [=[ CV:run("do_upload") ]=]) ]])
                GUI.button("  restart map", [[ GUI.show("restart_map") ]])
                GUI.button("  editing commands", [[ GUI.show("editing") ]])
            ''')
        elif check_server_terminated():
            Module.server_proc = None
            log(logging.ERROR, "Local server terminated due to an error")
示例#6
0
# Prepare

bot = Bot(CHANNEL, NICKNAME, SERVER, PORT)

# Disconnect process


def leave_irc(sender, **kwargs):
    try:
        bot.disconnect()
    except Exception, e:
        log(logging.ERROR, "IRC plugin error: " + str(e))


shutdown.connect(leave_irc, weak=False)

# Handle our own text messages


def get_client_name(client_number):
    try:
        client = Clients.get(client_number)
        return client.username
    except Exception, e:
        return '?'


def get_instance_name():
    return '[' + INSTANCE_NAME + '] '
示例#7
0
            text = text[len(INDICATOR):].lstrip()
            main_actionqueue.add_action(lambda : send_intensity_message(speaker, text))


# Prepare

bot = Bot(CHANNEL, NICKNAME, SERVER, PORT)

# Disconnect process

def leave_irc(sender, **kwargs):
    try:
        bot.disconnect()
    except Exception, e:
        log(logging.ERROR, "IRC plugin error: " + str(e));
shutdown.connect(leave_irc, weak=False)

# Handle our own text messages

def get_client_name(client_number):
    try:
        client = Clients.get(client_number)
        return client.username
    except Exception, e:
        return '?'

def get_instance_name():
    return '[' + INSTANCE_NAME + '] '

def on_text_message(sender, **kwargs):
    client_number = kwargs['client_number']
示例#8
0
import os, sys, shutil

from intensity.signals import shutdown


GRACEFUL_SHUTDOWN_INDICATOR = "-----====Shutdown was graceful====-----"
MAX_UPLOAD_LOG_SIZE = 80*100

# On normal shutdown, output a marker that it was graceful
def write_shutdown_graceful(sender, **kwargs):
    print "--"
    print GRACEFUL_SHUTDOWN_INDICATOR
    print "--"


shutdown.connect(write_shutdown_graceful, weak=False)


# Check last log file, if there is one, and upload error log if it wasn't graceful

# Test for an ungraceful shutdown last time, and update master if so
def test_last_shutdown_graceful():
    try:
        log_filename = sys.argv[2]
    except IndexError:
        print "NOTE: No previous log file provided, so no way to check for prior crash and to upload log to master"
        return True # Continue as if all is well, oblivious to it all

    print "Checking previous log for crash:", log_filename
    if not os.path.exists(log_filename):
        return True # No log, so assume all ok
示例#9
0
# 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)