# Path: mrq/config.py
# def add_parser_args(parser, config_type):
#     def add_argument(self, *args, **kwargs):
# def get_config(
#         sources=(
#             "file",
#             "env"),
#         env_prefix="MRQ_",
#         file_path=None,
#         parser=None,
#         extra=None,
#         config_type=None):
#         def print_profiling():
# class ArgumentParserIgnoringDefaults(argparse.ArgumentParser):
# 
# Path: mrq/utils.py
# @memoize_single_argument
# def load_class_by_path(taskpath):
#     """ Given a taskpath, returns the main task class. """
# 
#     return getattr(
#         importlib.import_module(
#             re.sub(
#                 r"\.[^.]+$",
#                 "",
#                 taskpath)),
#         re.sub(
#             r"^.*\.",
#             "",
#             taskpath))
# 
# Path: mrq/context.py
# def set_current_config(config):
#     _GLOBAL_CONTEXT["config"] = config
# 
#     if config["add_network_latency"] != "0" and config["add_network_latency"]:
#         from mrq.monkey import patch_network_latency
#         patch_network_latency(config["add_network_latency"])
# 
#     if config["print_mongodb"] or config["trace_io"]:
#         from mrq.monkey import patch_pymongo
#         patch_pymongo(config)
# 
#     if config["trace_io"]:
#         from mrq.monkey import patch_io_all
#         patch_io_all(config)
# 
# def set_logger_config():
#     config = _GLOBAL_CONTEXT["config"]
#     if config.get("quiet"):
#         log.disabled = True
#     else:
#         log_format = config["log_format"]
#         logging.basicConfig(format=log_format)
#         log.setLevel(getattr(logging, config["log_level"]))
# 
#         handlers = config["log_handlers"].keys() if config["log_handlers"] else [config["log_handler"]]
#         for handler in handlers:
#             handler_class = load_class_by_path(handler)
#             handler_config = config["log_handlers"].get(handler, {})
#             handler_format = handler_config.pop("format", log_format)
#             handler_level = getattr(logging, handler_config.pop("level", config["log_level"]))
#             log_handler = handler_class(**handler_config)
#             formatter = logging.Formatter(handler_format)
#             log_handler.setFormatter(formatter)
#             log_handler.setLevel(handler_level)
#             log.addHandler(log_handler)


import os
import sys
import tempfile
import signal
import psutil
import argparse
import pipes
from future.builtins import str
from gevent import monkey
from mrq import config
from mrq.utils import load_class_by_path
from mrq.context import set_current_config, set_logger_config
        from mrq.supervisor import Supervisor
#!/usr/bin/env python
is_pypy = '__pypy__' in sys.builtin_module_names

# Needed to make getaddrinfo() work in pymongo on Mac OS X
# Docs mention it's a better choice for Linux as well.
# This must be done asap in the worker
if "GEVENT_RESOLVER" not in os.environ and not is_pypy:
    os.environ["GEVENT_RESOLVER"] = "ares"

monkey.patch_all()


sys.path.insert(0, os.getcwd())



def main():


# Path: mrq/config.py
# def add_parser_args(parser, config_type):
#     def add_argument(self, *args, **kwargs):
# def get_config(
#         sources=(
#             "file",
#             "env"),
#         env_prefix="MRQ_",
#         file_path=None,
#         parser=None,
#         extra=None,
#         config_type=None):
#         def print_profiling():
# class ArgumentParserIgnoringDefaults(argparse.ArgumentParser):
# 
# Path: mrq/utils.py
# @memoize_single_argument
# def load_class_by_path(taskpath):
#     """ Given a taskpath, returns the main task class. """
# 
#     return getattr(
#         importlib.import_module(
#             re.sub(
#                 r"\.[^.]+$",
#                 "",
#                 taskpath)),
#         re.sub(
#             r"^.*\.",
#             "",
#             taskpath))
# 
# Path: mrq/context.py
# def set_current_config(config):
#     _GLOBAL_CONTEXT["config"] = config
# 
#     if config["add_network_latency"] != "0" and config["add_network_latency"]:
#         from mrq.monkey import patch_network_latency
#         patch_network_latency(config["add_network_latency"])
# 
#     if config["print_mongodb"] or config["trace_io"]:
#         from mrq.monkey import patch_pymongo
#         patch_pymongo(config)
# 
#     if config["trace_io"]:
#         from mrq.monkey import patch_io_all
#         patch_io_all(config)
# 
# def set_logger_config():
#     config = _GLOBAL_CONTEXT["config"]
#     if config.get("quiet"):
#         log.disabled = True
#     else:
#         log_format = config["log_format"]
#         logging.basicConfig(format=log_format)
#         log.setLevel(getattr(logging, config["log_level"]))
# 
#         handlers = config["log_handlers"].keys() if config["log_handlers"] else [config["log_handler"]]
#         for handler in handlers:
#             handler_class = load_class_by_path(handler)
#             handler_config = config["log_handlers"].get(handler, {})
#             handler_format = handler_config.pop("format", log_format)
#             handler_level = getattr(logging, handler_config.pop("level", config["log_level"]))
#             log_handler = handler_class(**handler_config)
#             formatter = logging.Formatter(handler_format)
#             log_handler.setFormatter(formatter)
#             log_handler.setLevel(handler_level)
#             log.addHandler(log_handler)


# Path: mrq/bin/mrq_worker.py
import os
import sys
import tempfile
import signal
import psutil
import argparse
import pipes
from future.builtins import str
from gevent import monkey
from mrq import config
from mrq.utils import load_class_by_path
from mrq.context import set_current_config, set_logger_config
        from mrq.supervisor import Supervisor

#!/usr/bin/env python
is_pypy = '__pypy__' in sys.builtin_module_names

# Needed to make getaddrinfo() work in pymongo on Mac OS X
# Docs mention it's a better choice for Linux as well.
# This must be done asap in the worker
if "GEVENT_RESOLVER" not in os.environ and not is_pypy:
    os.environ["GEVENT_RESOLVER"] = "ares"

monkey.patch_all()


sys.path.insert(0, os.getcwd())



def main():


    parser = argparse.ArgumentParser(description='Start a MRQ worker')