<commit_before># Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from concurrent.futures import TimeoutError
from urllib.parse import urlunparse
import atexit
import logging
import os
import re
import signal
import sys

from bndl.net.aio import get_loop, get_loop_thread, stop_loop, run_coroutine_threadsafe
from bndl.net.connection import urlparse
from bndl.net.rmi import RMINode
from bndl.util.funcs import noop
from bndl.util.threads import dump_threads
import resource


logger = logging.getLogger(__name__)


class Executor(RMINode):
    def __init__(self, *args, **kwargs):
        from bndl.compute.blocks import BlockManager
        from bndl.compute.broadcast import BroadcastManager
        from bndl.compute.memory import LocalMemoryManager
        from bndl.compute.shuffle import ShuffleManager
        from bndl.compute.tasks import Tasks

        super().__init__(*args, **kwargs)
        self.memory_manager = LocalMemoryManager()
        self.services['blocks'] = BlockManager(self)
        self.services['broadcast'] = BroadcastManager(self)
        self.services['shuffle'] = ShuffleManager(self)
        self.services['tasks'] = Tasks(self)
        self.services['memory'] = self.memory_manager


def _executor_address(worker_address, executor_id):
    worker_address = urlparse(worker_address)
    executor_address = list(worker_address)
    executor_port = worker_address.port + int(executor_id)
    executor_address[1] = re.sub(':\d+', ':%s' % (executor_port), executor_address[1])
    executor_address = urlunparse(executor_address)
    return executor_address


def main():
    # Make sure numpy, scipy etc don't ask OMP to create as much threads as there are cores as BNDL is
    # already parallelizing work.
    if 'OMP_NUM_THREADS' not in os.environ:
        os.environ['OMP_NUM_THREADS'] = '2'

    # Set the soft limit for the maximum number of open files to the hard limit.
    for r in (resource.RLIMIT_NOFILE,):
        low, high = resource.getrlimit(r)
        if low < high or high == resource.RLIM_INFINITY:
            resource.setrlimit(r, (high, high))

    worker_address, executor_id = sys.argv[1:]
    executor_address = _executor_address(worker_address, executor_id)

    loop = get_loop(start=True)
    executor = Executor(
        node_type='executor',
        addresses=[executor_address],
        seeds=[worker_address],<commit_msg>also ask for more procs<commit_after># Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from concurrent.futures import TimeoutError
from urllib.parse import urlunparse
import atexit
import logging
import os
import re
import signal
import sys

from bndl.net.aio import get_loop, get_loop_thread, stop_loop, run_coroutine_threadsafe
from bndl.net.connection import urlparse
from bndl.net.rmi import RMINode
from bndl.util.funcs import noop
from bndl.util.threads import dump_threads
import resource


logger = logging.getLogger(__name__)


class Executor(RMINode):
    def __init__(self, *args, **kwargs):
        from bndl.compute.blocks import BlockManager
        from bndl.compute.broadcast import BroadcastManager
        from bndl.compute.memory import LocalMemoryManager
        from bndl.compute.shuffle import ShuffleManager
        from bndl.compute.tasks import Tasks

        super().__init__(*args, **kwargs)
        self.memory_manager = LocalMemoryManager()
        self.services['blocks'] = BlockManager(self)
        self.services['broadcast'] = BroadcastManager(self)
        self.services['shuffle'] = ShuffleManager(self)
        self.services['tasks'] = Tasks(self)
        self.services['memory'] = self.memory_manager


def _executor_address(worker_address, executor_id):
    worker_address = urlparse(worker_address)
    executor_address = list(worker_address)
    executor_port = worker_address.port + int(executor_id)
    executor_address[1] = re.sub(':\d+', ':%s' % (executor_port), executor_address[1])
    executor_address = urlunparse(executor_address)
    return executor_address


def main():
    # Make sure numpy, scipy etc don't ask OMP to create as much threads as there are cores as BNDL is
    # already parallelizing work.
    if 'OMP_NUM_THREADS' not in os.environ:
        os.environ['OMP_NUM_THREADS'] = '2'

    # Set the soft limit for the maximum number of open files to the hard limit.
    for r in (resource.RLIMIT_NOFILE, resource.RLIMIT_NPROC):
        low, high = resource.getrlimit(r)
        if low < high or high == resource.RLIM_INFINITY:
            resource.setrlimit(r, (high, high))

    worker_address, executor_id = sys.argv[1:]
    executor_address = _executor_address(worker_address, executor_id)

    loop = get_loop(start=True)
    executor = Executor(
        node_type='executor',
        addresses=[executor_address],
        seeds=[worker_address],
{'fraction_non_alphanumeric': 0.08385200553250345, 'fraction_numerical': 0.0027662517289073307, 'mean_word_length': 3.89010989010989, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1171031', 'n_tokens_mistral': 1717, 'n_tokens_neox': 1701, 'n_words': 526}