I have a problem I can't wrap my head around

when I ssh into remote server:

muad@podde:~$ ssh hub
[venv] muad@hub:~ % cd tonder
[venv] muad@hub:~/tonder % python manage.py start_bot
[bot starts fine and the process stays attached]
muad@podde:~$ xkill                                                        
       │······················
Select the window whose client you wish to kill with button 1....          
       │······················
xkill:  killing creator of resource 0x140000f   
 [whoops :o] 
muad@podde:~$ ssh hub
[venv] muad@hub:~ % ps aux
USER    PID %CPU %MEM   VSZ   RSS TT  STAT STARTED     TIME COMMAND
muad  61477  2.2  0.4 84616 65612  3  S+J  Sun08   75:57.59 
/usr/home/muad/venv/bin/python manage.py runserver 192.168.1.113:8000 
(python3.7)
muad  65872  1.7  0.3 71328 57092  9- S+J  07:42    0:00.74 python 
manage.py start_bot l1 (python3.7) <---- WHYYY is not this one dead as a 
door nail?

PID 65872 does not die, is this some Django voodo trick and if that is the 
case how/why/what ehm huh?



-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/908f4feb-9bbe-4dc1-a8da-73e25c72e036%40googlegroups.com.
import irc3
import json
import logging

import irc3.plugins.command
from django.conf import settings
from pathlib import Path

#added for debugging #TODO find a way to check if the code is in debug or not
import pudb
#from irc.models import Bot, PluginSetting


class IrcBot:
    def __init__(self):
        self.d = 1
        #self.config_file = Path(f'irc/config/bot.conf')

    def load_config(self, bot_nick):
        file = Path(f'irc/config/{bot_nick}.json')
        if not file.is_file():
            logging.critical(f"we don't have a file {file}")
            return False
            #self.save_json()
        with open(file, "r") as read_file:
            self.json_data = json.load(read_file)
            return self.json_data

    def start_bot(self, bot_nick):
        print(bot_nick)
        config = self.load_config(bot_nick)
        plugin_file = Path(f'irc/plugins/tools.py')
        if config:
            if plugin_file.is_file():
                irc = irc3.IrcBot.from_config(config)
                irc.run(forever=True)
            else:
                pudb.set_trace()
                logging.critical("the tools plugin is missing go and fix it!")
        else:
            pudb.set_trace()
            logging.critical(f"there is no bot with nick: {bot_nick}")

            # [15:46] <~lsw> non-ssl ports are 4367, 4368, 4369
            # [15:46] <~lsw> ssl ports are 4397, 4399



from django.core.management.base import BaseCommand
import os
from irc.models import Bot
from irc.bot import IrcBot
from irc.botlib.common import cm

# imported for pudb debugger
import pudb

class Command(BaseCommand):
    help = 'Start bot'

    def add_arguments(self, parser):
        parser.add_argument(
            'bot_nick', type=str, help='What bot do you want to start use the bot id to choose')

    def handle(self, *args, **kwargs):
        bot_nick = kwargs['bot_nick']
        bot, new_entry = Bot.objects.get_or_create(nick=bot_nick, config_file=f'irc/config/{bot_nick}.json')
        if cm.check_pid(bot.pid) == False or bot.pid == 666:    
            bot.pid = os.getpid()
            bot.save()
            # TODO need to check if bot already running if so please kill it or rename nick of it
            IrcBot().start_bot(bot_nick=bot_nick)
            bot.pid = 666
            bot.save()
        else:
            pudb.set_trace()
            print("we have an bot running with that nick")

Reply via email to