Example #1
0
    def run_command(self):
        settings = get_settings(self.arguments.configuration)
        app = self.make_app(settings)

        if self.arguments.line_profiler:
            if not HAS_LINE_PROFILER:
                sys.stderr.write(
                    'You must first install line_profiler for the --line-profiler option to work.\n'
                    'Use `pip install line_profiler` to install line_profiler.\n'
                )
                return 1
            self.line_profiler = line_profiler.LineProfiler()
            for func in profile.get_profilable_functions():
                if fnmatch(get_dotted_name(func),
                           self.arguments.line_profiler_matcher or '*'):
                    self.line_profiler.add_function(func)
            self.line_profiler.enable_by_count()

        run_func = self.__run
        if self.arguments.monitor:
            if not HAS_AIOMONITOR:
                sys.stderr.write(
                    'You must install aiomonitor for the '
                    '--monitor option to work.\n'
                    'Use `pip install aiomonitor` to install aiomonitor.\n')
                return 1
            run_func = self.__run_with_monitor

        if self.arguments.profile:
            self.profiler = cProfile.Profile()
            self.profiler.runcall(run_func, app, settings)
        else:
            run_func(app, settings)
Example #2
0
    def run_command(self, settings=None, loop=None):
        if loop is not None:
            self.loop = loop
        if settings is None:
            settings = get_settings(self.arguments.configuration,
                                    self.arguments.override)
        if settings.get("loop_policy"):
            loop_policy = resolve_dotted_name(settings["loop_policy"])
            asyncio.set_event_loop_policy(loop_policy())

        app = self.make_app(settings)

        if self.arguments.line_profiler:
            if not HAS_LINE_PROFILER:
                sys.stderr.write(
                    "You must first install line_profiler for the --line-profiler option to work.\n"
                    "Use `pip install line_profiler` to install line_profiler.\n"
                )
                return 1
            self.line_profiler = line_profiler.LineProfiler()
            for func in profile.get_profilable_functions():
                if fnmatch(get_dotted_name(func),
                           self.arguments.line_profiler_matcher or "*"):
                    self.line_profiler.add_function(func)
            self.line_profiler.enable_by_count()

        run_func = self.__run
        if self.arguments.monitor:
            if not HAS_AIOMONITOR:
                sys.stderr.write(
                    "You must install aiomonitor for the "
                    "--monitor option to work.\n"
                    "Use `pip install aiomonitor` to install aiomonitor.\n")
                return 1
            run_func = self.__run_with_monitor

        if self.arguments.profile:
            self.profiler = cProfile.Profile()
            self.profiler.runcall(run_func, app, settings)
            if self.arguments.profile_output:
                self.profiler.dump_stats(self.arguments.profile_output)
            else:
                # dump to screen
                self.profiler.print_stats(-1)
        else:
            run_func(app, settings)

        if self.line_profiler is not None:
            self.line_profiler.disable_by_count()
            if self.arguments.line_profiler_output:
                self.line_profiler.dump_stats(
                    self.arguments.line_profiler_output)
            else:
                self.line_profiler.print_stats()
Example #3
0
    def run_command(self, settings=None, loop=None):
        if loop is not None:
            self.loop = loop
        if settings is None:
            settings = get_settings(self.arguments.configuration, self.arguments.override)
        if settings.get('loop_policy'):
            loop_policy = resolve_dotted_name(settings['loop_policy'])
            asyncio.set_event_loop_policy(loop_policy())

        app = self.make_app(settings)

        if self.arguments.line_profiler:
            if not HAS_LINE_PROFILER:
                sys.stderr.write(
                    'You must first install line_profiler for the --line-profiler option to work.\n'
                    'Use `pip install line_profiler` to install line_profiler.\n'
                )
                return 1
            self.line_profiler = line_profiler.LineProfiler()
            for func in profile.get_profilable_functions():
                if fnmatch(get_dotted_name(func), self.arguments.line_profiler_matcher or '*'):
                    self.line_profiler.add_function(func)
            self.line_profiler.enable_by_count()

        run_func = self.__run
        if self.arguments.monitor:
            if not HAS_AIOMONITOR:
                sys.stderr.write(
                    'You must install aiomonitor for the '
                    '--monitor option to work.\n'
                    'Use `pip install aiomonitor` to install aiomonitor.\n')
                return 1
            run_func = self.__run_with_monitor

        if self.arguments.profile:
            self.profiler = cProfile.Profile()
            self.profiler.runcall(run_func, app, settings)
        else:
            run_func(app, settings)
Example #4
0
 def _run(self, arguments, settings, app):
     port = arguments.port or settings.get('address', settings.get('port'))
     host = arguments.host or settings.get('host', '0.0.0.0')
     if arguments.line_profiler:
         if not HAS_LINE_PROFILER:
             sys.stderr.write(
                 'You must first install line_profiler for the --line-profiler option to work.\n'
                 'Use `pip install line_profiler` to install line_profiler.\n'
             )
             return 1
         self.line_profiler = line_profiler.LineProfiler()
         for func in profile.get_profilable_functions():
             if fnmatch(get_dotted_name(func),
                        arguments.line_profiler_matcher or '*'):
                 self.line_profiler.add_function(func)
         self.line_profiler.enable_by_count()
     if arguments.profile:
         self.profiler = cProfile.Profile()
         self.profiler.runcall(
             web.run_app,
             app,
             host=host,
             port=port,
             loop=self.get_loop(),
             access_log_format=settings.get('access_log_format'))
     else:
         try:
             web.run_app(
                 app,
                 host=host,
                 port=port,
                 loop=self.get_loop(),
                 access_log_format=settings.get('access_log_format'))
         except asyncio.CancelledError:
             # server shut down, we're good here.
             pass