def shutdown(self):
     """ Waits for the current thread execution to become None or else will not shutdown properly"""
     self._disable_dump = True  # will not write to run time options
     self.stop = True  # signals all long_running operations to not execute, os calls will not occur either
     while self._provider.current_thread is not None:
         logger.warning('waiting for thread to stop')
         time.sleep(5)
     self._scheduler.shutdown()
     self._shutdown = True
 async def st():
     tasks = [
         task for task in asyncio.Task.all_tasks()
         if task is not asyncio.tasks.Task.current_task()
     ]
     list(map(lambda task: task.cancel(), tasks))
     results = await asyncio.gather(*tasks, return_exceptions=True)
     for r in results:
         if isinstance(r, str):
             logger.warning("Task {}".format(r))
Exemple #3
0
    def wrapped(update, context, *args, **kwargs):
        user_id = update.effective_user.id
        if user_id not in config['admin_list']:
            logger.warning("[RESTRICTION CHAT] User={} "
                           "called command={} "
                           "in module={} function={}"
                           .format(update.message.from_user.id,
                                   update.message.text,
                                   func.__module__,
                                   func.__name__))

            return
        return func(update, context, *args, **kwargs)
Exemple #4
0
 async def load(self, ctx, ext):
     """Load an Extension. """
     print(f'{ctx.author.name} loading {ext}')
     try:
         check = path(f'extensions/{ext}.py')
         if not check.exists() or ext == 'AdminCommands':
             return await ctx.send(f'{ext} is not a valid extension.')
         self.bot.load_extension(f'extensions.{ext}')
         logger.warning(f'{ext} Loaded by {ctx.author.name}')
         print(f'{ext} Loaded')
         return await ctx.send(f'{ext} Loaded')
     except Exception as e:
         logger.error(f'Error loading {ext}. Error: {e}')
         logger.error(traceback.print_exc())
         return print(e)
Exemple #5
0
 async def reload(self, ctx, ext):
     """ Reload an extension. """
     print(f'{ctx.author.name} reloading {ext}')
     try:
         check = path(f'extensions/{ext}.py')
         if not check.exists():
             return await ctx.send(f'{ext} is not a valid extension')
         self.bot.unload_extension(f'extensions.{ext}')
         print(f'{ext} Unloaded')
         self.bot.load_extension(f'extensions.{ext}')
         print(f'{ext} Loaded')
         logger.warning(f'{ext} Reloaded by {ctx.author.name}')
         return await ctx.send(f'{ext} Reloaded')
     except Exception as e:
         logger.error(f'Error reloading {ext}. Error: {e}')
         logger.error(traceback.print_exc())
         print(e)
 def shutdown(self):
     """ Waits for the current thread execution to become None or else will not shutdown properly"""
     self._disable_dump = True  # will not write to run time options
     self.stop = True  # signals all long_running operations to not execute, os calls will not occur either
     while self._provider.current_thread is not None:
         logger.warning('Waiting for bot thread to stop')
         time.sleep(5)
     logger.info("Shutdown started")
     self._task_runner.shutdown()
     self._loop.call_soon_threadsafe(self._loop.stop)
     try:
         self._scheduler.shutdown()
     except SchedulerNotRunningError:
         pass
     if self._loop_thread:
         self._loop_thread.join()
     while self._loop.is_running():
         pass
     self._loop.close()
     logger.info("Shutdown complete")
     self._shutdown = True
Exemple #7
0
def log_errors(update, error):
    logger.warning('Update "%s" caused error "%s"', update, error)