예제 #1
0
                                   'r').read().strip().split('\n')
            else:
                user_agents = [args.user_agent]
        else:
            user_agents = generate_user_agent
        locks = [Lock() for _ in range(4)]
        logger_lock = Lock()
        drivers = []
        proxies = []
        watched_ads = 0
        for i in range(args.threads):
            t = Thread(target=bot, args=(i + 1, ))
            t.daemon = True
            t.start()
        if args.debug:
            for t in list_threads()[1:]:
                t.join()
        else:
            while True:
                with logger_lock:
                    print('\n' * 100)
                    stdout.write('Watched ads: %d' % watched_ads)
                    stdout.flush()
                sleep(args.refresh)
    except SystemExit as e:
        exit(int(str(e)))
    except KeyboardInterrupt:
        exit(0)
    except:
        exit(1)
예제 #2
0
    async def command(client, message):
        thread_count_by_type = {}
        thread_count = 0

        for thread in list_threads():
            thread_count += 1
            thread_type = thread.__class__
            thread_count_by_type[thread_type] = thread_count_by_type.get(
                thread_type, 0) + 1

        description = []

        main_thread_count = thread_count_by_type.pop(MainThreadType, 0)
        event_thread_count = thread_count_by_type.pop(EventThread, 0)

        event_loop_executor_count = 0

        add_space = False

        if main_thread_count or event_thread_count:
            add_space = True
            description.append('**Main threads**:\n')

            if main_thread_count:
                description.append('Main threads: ')
                description.append(repr(main_thread_count))
                description.append('\n')

            if event_thread_count:
                description.append('Event threads: ')
                description.append(repr(event_thread_count))
                description.append('\n')

                for thread in list_threads():
                    if type(thread) is EventThread:
                        event_loop_executor_count += thread.used_executor_count + thread.free_executor_count

            description.append(
                f'--------------------\n'
                f'Total: {main_thread_count+event_thread_count}')

        executor_thread_count = thread_count_by_type.pop(ExecutorThread, 0)
        if executor_thread_count:
            if add_space:
                description.append('\n\n')
            else:
                add_space = True

            other_executors = executor_thread_count

            description.append('**Executors:**\n')

            if event_loop_executor_count:
                other_executors -= event_loop_executor_count
                description.append('Event thread executors: ')
                description.append(repr(event_loop_executor_count))
                description.append('\n')

            if DB_ENGINE.uses_single_worker:
                other_executors -= 1
                description.append('Database engine worker: 1\n')

            if other_executors > 0:
                description.append('Other executors: ')
                description.append(repr(other_executors))
                description.append('\n')

            description.append(f'--------------------\n'
                               f'Total: {executor_thread_count}')

        if thread_count_by_type:
            if add_space:
                description.append('\n\n')
            else:
                add_space = True

            description.append('**Other thread types**:\n')

            thread_count_by_type = sorted(thread_count_by_type.items(),
                                          key=lambda item: item[1])

            total_leftover = 0
            for item in thread_count_by_type:
                total_leftover += item[1]

            displayed_thread_types_count = 0
            non_displayed_thread_count = total_leftover

            while True:
                if non_displayed_thread_count == 0:
                    break

                if displayed_thread_types_count == 10:
                    description.append('Other: ')
                    description.append(repr(non_displayed_thread_count))
                    description.append('\n')
                    break

                type_, count = thread_count_by_type.pop()
                non_displayed_thread_count -= count

                thread_type_name = type_.__name__
                if len(thread_type_name) > 32:
                    thread_type_name = thread_type_name[:32] + '...'

                description.append(thread_type_name)
                description.append(': ')
                description.append(repr(count))
                description.append('\n')

            description.append('--------------------\nTotal: ')
            description.append(repr(total_leftover))

        if add_space:
            description.append('\n\n**--------------------**\n')

        description.append('**Total**: ')
        description.append(repr(thread_count))

        embed = Embed('Threads', ''.join(description), color=STAT_COLOR)

        await client.message_create(message.channel, embed=embed)