Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/isida/vi.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordiSabler <dissy@ya.ru>2017-02-24 15:40:33 +0300
committerdiSabler <dissy@ya.ru>2017-02-24 15:40:33 +0300
commit759f1cfd80fc33acd80bf9df59516e6a7984901c (patch)
tree91827a11064dce87539669e33b92d9f8cd9d3e88
parent0e74ee29477a3fbb7a4c152984ce506bdbb335b3 (diff)
fix: kernel reload from thread
-rw-r--r--kernel.py28
-rw-r--r--plugins/bot_info.py2
-rw-r--r--plugins/service.py19
3 files changed, 27 insertions, 22 deletions
diff --git a/kernel.py b/kernel.py
index 2b01284..02aa92f 100644
--- a/kernel.py
+++ b/kernel.py
@@ -757,18 +757,20 @@ base_type = 'NoDB' # Bot's base type
www_get_timeout = 15 # Timeout for web requests
size_overflow = 262144 # Web page limit in bytes
#http_proxy = {'host':'127.0.0.1','port':3128,'user':None,'password':None}
-# # Proxy settings
+# # Proxy settings
user_agent = 'Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/39.0.2171.95 Safari/537.36'
-# # User agent for web requests
+# # User agent for web requests
MIN_TIMEOUT = 1 # Minimal timeout between request updates
MAX_TIMEOUT = 15 # Maximal timeout between request updates
TIMEOUT = 1 # Default timeout between request updates
LAST_MESSAGE = time.time() # Last message time
TIMEOUT_DIFF = 60 # Little sleep every 60 seconds
TIMEOUT_STEP = 1.3 # Size of update time sleep
-CYCLES = 0
-THREAD_COUNT = 0
-THREAD_ERROR_COUNT = 0
+CYCLES = 0 # Work cycles
+THREAD_COUNT = 0 # Executed threads
+THREAD_ERROR_COUNT = 0 # Threads with error
+GAME_OVER = False # Bot's status
+BOT_EXIT_TYPE = '' # Reason for bot's kernel exit
# --- Init ------------------------------------------------------------------- #
try:
@@ -830,9 +832,15 @@ pprint('-'*50,'blue')
pprint('Let\'s begin!','white')
# --- Main cycle ------------------------------------------------------------- #
-while True:
+while not GAME_OVER:
try:
check_updates()
+ if (time.time() - LAST_MESSAGE) > TIMEOUT_DIFF and TIMEOUT <= MAX_TIMEOUT:
+ TIMEOUT = TIMEOUT * TIMEOUT_STEP
+ LAST_MESSAGE = time.time()
+ pprint('*** Sleep time: %.02f' % TIMEOUT, 'brown')
+ CYCLES += 1
+ time.sleep(TIMEOUT)
except KeyboardInterrupt:
pprint('Shutdown by CTRL+C...','bright_red')
time.sleep(1)
@@ -846,11 +854,7 @@ while True:
logging.exception(' [%s] ' % timeadd(tuple(time.localtime())))
if HALT_ON_EXCEPTION:
raise
- if (time.time() - LAST_MESSAGE) > TIMEOUT_DIFF and TIMEOUT <= MAX_TIMEOUT:
- TIMEOUT = TIMEOUT * TIMEOUT_STEP
- LAST_MESSAGE = time.time()
- pprint('*** Sleep time: %.02f' % TIMEOUT, 'brown')
- CYCLES += 1
- time.sleep(TIMEOUT)
+
+sys.exit(BOT_EXIT_TYPE)
# The end is near!
diff --git a/plugins/bot_info.py b/plugins/bot_info.py
index e342210..0ca2643 100644
--- a/plugins/bot_info.py
+++ b/plugins/bot_info.py
@@ -22,7 +22,7 @@
# --------------------------------------------------------------------------- #
def cmd_bot_info(raw_in):
- msg = '🤖 %s %s\n🖥️ %s' % (botName, get_bot_version(), get_os_version().replace(' / ','\n🐍 '))
+ msg = '🤖 %s %s' % (botName, get_bot_version())
msg += '\n🔄 Cycles: %s' % CYCLES
msg += '\n▶️ Threads: %s' % THREAD_COUNT
msg += '\n❗️ Error threads: %s' % THREAD_ERROR_COUNT
diff --git a/plugins/service.py b/plugins/service.py
index a4abfb6..7176275 100644
--- a/plugins/service.py
+++ b/plugins/service.py
@@ -21,20 +21,21 @@
# #
# --------------------------------------------------------------------------- #
-def cmd_update(raw_in):
- send_msg(raw_in,'Let\'s update!')
+def raw_bot_restart(raw_in, msg, status):
+ global GAME_OVER, BOT_EXIT_TYPE
+ send_msg(raw_in, msg)
check_updates()
- sys.exit('update')
+ GAME_OVER = True
+ BOT_EXIT_TYPE = status
+
+def cmd_update(raw_in):
+ raw_bot_restart(raw_in, 'Let\'s update!', 'update')
def cmd_restart(raw_in):
- send_msg(raw_in,'Let\'s restart!')
- check_updates()
- sys.exit('restart')
+ raw_bot_restart(raw_in, 'Let\'s restart!', 'restart')
def cmd_quit(raw_in):
- send_msg(raw_in,'See Ya!')
- check_updates()
- sys.exit('exit')
+ raw_bot_restart(raw_in, 'See Ya!', 'exit')
commands = [['update', cmd_update, True, 'raw', 'Update bot from repository.'],
['restart', cmd_restart, True, 'raw', 'Restart bot.'],