# Path: sio/workers/runner.py
# def _run_filters(key, environ):
# def _add_meta(environ):
# def _save_failure(exc, environ):
# def _print_environ(environ):
# def run(environ):
# def main():
# 
# Path: sio/protocol/rpc.py
# class TimeoutError(Exception):
# class ProtocolError(Exception):
# class RemoteError(Exception):
# class NoSuchMethodError(RemoteError):
# class WorkerRPC(NetstringReceiver):
#     def __init__(self, err, tb=None, uid=None):
#     def __init__(self, err=None, uid=None):
# def makeRemoteException(msg, uid=None):
#     def __init__(self, server=False, timeout=DEFAULT_TIMEOUT):
#     def connectionMade(self):
#     def connectionLost(self, reason):
#     def _processMessage(self, msg):
#     def getHelloData(self):
#     def stringReceived(self, string):
#     def _reply(self, value, request=None):
#     def _replyError(self, err, request=None):
#     def _timeout(self, rid):
#     def sendMsg(self, msg_type, **kwargs):
#     def call(self, cmd, *args, **kwargs):
#         def cb(ignore):
#     MAX_LENGTH = 2 ** 20  # 1MB should be enough
#     DEFAULT_TIMEOUT = 30


from twisted.internet.protocol import ReconnectingClientFactory
from twisted.internet import threads
from sio.workers import runner
from sio.protocol import rpc
from twisted.logger import Logger, LogLevel
import platform
import six
            'can_run_cpu_exec': self.factory.can_run_cpu_exec,
        }

    def cmd_run(self, env):
        job_type = env['job_type']
        if job_type == 'cpu-exec':
            if self.running:
                raise RuntimeError('Send cpu-exec job to busy worker')
            if not self.factory.can_run_cpu_exec:
                raise RuntimeError('Send cpu-exec job to worker which can\'t run it')
        if any(
            [(task['job_type'] == 'cpu-exec') for task in six.itervalues(self.running)]
        ):
            raise RuntimeError('Send job to worker already running cpu-exec job')
        task_id = env['task_id']
        log.info('running {job_type} {tid}', job_type=job_type, tid=task_id)
        self.running[task_id] = env
        d = threads.deferToThread(_runner_wrap, env)

        # Log errors, but pass them to sioworkersd anyway
        def _error(x):
            log.failure('Error during task execution:', x, LogLevel.warn)
            return x

        def _done(x):
            del self.running[task_id]
            log.info('{tid} done.', tid=task_id)
            return x

        d.addBoth(_done)

# Path: sio/workers/runner.py
# def _run_filters(key, environ):
# def _add_meta(environ):
# def _save_failure(exc, environ):
# def _print_environ(environ):
# def run(environ):
# def main():
# 
# Path: sio/protocol/rpc.py
# class TimeoutError(Exception):
# class ProtocolError(Exception):
# class RemoteError(Exception):
# class NoSuchMethodError(RemoteError):
# class WorkerRPC(NetstringReceiver):
#     def __init__(self, err, tb=None, uid=None):
#     def __init__(self, err=None, uid=None):
# def makeRemoteException(msg, uid=None):
#     def __init__(self, server=False, timeout=DEFAULT_TIMEOUT):
#     def connectionMade(self):
#     def connectionLost(self, reason):
#     def _processMessage(self, msg):
#     def getHelloData(self):
#     def stringReceived(self, string):
#     def _reply(self, value, request=None):
#     def _replyError(self, err, request=None):
#     def _timeout(self, rid):
#     def sendMsg(self, msg_type, **kwargs):
#     def call(self, cmd, *args, **kwargs):
#         def cb(ignore):
#     MAX_LENGTH = 2 ** 20  # 1MB should be enough
#     DEFAULT_TIMEOUT = 30


# Path: sio/protocol/worker.py
from twisted.internet.protocol import ReconnectingClientFactory
from twisted.internet import threads
from sio.workers import runner
from sio.protocol import rpc
from twisted.logger import Logger, LogLevel
import platform
import six

            'can_run_cpu_exec': self.factory.can_run_cpu_exec,
        }

    def cmd_run(self, env):
        job_type = env['job_type']
        if job_type == 'cpu-exec':
            if self.running:
                raise RuntimeError('Send cpu-exec job to busy worker')
            if not self.factory.can_run_cpu_exec:
                raise RuntimeError('Send cpu-exec job to worker which can\'t run it')
        if any(
            [(task['job_type'] == 'cpu-exec') for task in six.itervalues(self.running)]
        ):
            raise RuntimeError('Send job to worker already running cpu-exec job')
        task_id = env['task_id']
        log.info('running {job_type} {tid}', job_type=job_type, tid=task_id)
        self.running[task_id] = env
        d = threads.deferToThread(_runner_wrap, env)

        # Log errors, but pass them to sioworkersd anyway
        def _error(x):
            log.failure('Error during task execution:', x, LogLevel.warn)
            return x

        def _done(x):
            del self.running[task_id]
            log.info('{tid} done.', tid=task_id)
            return x

        d.addBoth(_done)

        d.addErrback(_error)