The multiprocessing worker initializer

    Parameters
    ----------
    inpaths : list of str
        A list of dataset paths.
    g_args : dict
        Global arguments.

    Returns
    -------
    None
355108
def init_worker(inpaths, g_args):
    
    global global_args
    global srcs
    global_args = g_args
    srcs = [rasterio.open(i) for i in inpaths]
561724
function(path) {
      var code = require('fs').readFileSync(path);
      var context = vm.createContext(initContext);
      context.flow = _conn.flow;
      vm.runInContext(code, context);
      for (var key in context) {
        if (!initContext[key]) {
          global[key] = context[key];
        }
      }
    }
118840
def init(main_dir: Path, logfile_path: Path, log_level: str):
    
    dynamic_data.reset()
    dynamic_data.init_dirs(main_dir, logfile_path)

    dynamic_data.check_dirs()

    tools.create_dir_rec(dynamic_data.MAIN_DIR)
    tools.create_dir_rec(dynamic_data.TEMP_DIR)
    tools.create_dir_rec(dynamic_data.DOWNLOAD_DIR)
    tools.create_dir_rec(dynamic_data.SAVESTAT_DIR)
    tools.create_dir_rec(Path.resolve(dynamic_data.LOGFILE_PATH).parent)
    dynamic_data.LOG_LEVEL = log_level
    logging.basicConfig(filename=dynamic_data.LOGFILE_PATH, filemode='a', level=dynamic_data.LOG_LEVEL,
                        format='%(asctime)s.%(msecs)03d | %(levelname)s - %(name)s | %(module)s.%(funcName)s: %('
                               'message)s',
                        datefmt='%Y.%m.%d %H:%M:%S')
    logging.captureWarnings(True)

    cores = multiprocessing.cpu_count()
    dynamic_data.USING_CORES = min(4, max(1, cores - 1))

    info = f"{static_data.NAME} {static_data.VERSION}\n\n" \
           f"System: {platform.system()} - {platform.version()} - {platform.machine()} - {cores} cores\n" \
           f"Python: {platform.python_version()} - {' - '.join(platform.python_build())}\n" \
           f"Arguments: main={main_dir.resolve()} | logfile={logfile_path.resolve()} | loglevel={log_level}\n" \
           f"Using cores: {dynamic_data.USING_CORES}\n\n"
    with dynamic_data.LOGFILE_PATH.open(mode='w', encoding="utf8") as writer:
        writer.write(info)

    dynamic_data.AVAIL_PLUGINS = APlugin.get_plugins()
404309
def threads_init(gtk=True):
    
    # enable X11 multithreading
    x11.XInitThreads()
    if gtk:
        from gtk.gdk import threads_init
        threads_init()
981785
def _load_start_paths(self):
        "  "
        if self._startup_paths:
            for path in self._startup_paths:
                if os.path.exists(path):
                    with open(path, 'rb') as f:
                        code = compile(f.read(), path, 'exec')
                        six.exec_(code, self.get_globals(), self.get_locals())
                else:
                    output = self.app.output
                    output.write('WARNING | File not found: {}\n\n'.format(path))
579379
static void initPaths() {
		if (config != null && config.getPaths() != null) {
			for (PathChain pathChain : config.getPaths()) {
				pathChain.validate(configName + " config"); // raises exception on misconfiguration
				if(pathChain.getPath() == null) {
					addSourceChain(pathChain);
				} else {
					addPathChain(pathChain);
				}
			}
		}
	}
802237
def initialize_path(self, path_num=None):
        
        for p in self.producers:
            p.initialize_path(path_num)
        # self.state = copy(self.initial_state)
        # self.state.path = path_num
        self.random.seed(hash(self.seed) + hash(path_num))
1212318
def _setup_paths(self, paths, filters=()):
    """"""
    for interpreter in self._matching(PythonInterpreter.all(paths), filters=filters):
      identity_str = str(interpreter.identity)
      pi = self._interpreter_from_relpath(identity_str, filters=filters)
      if pi is None:
        self._setup_interpreter(interpreter, identity_str)
        pi = self._interpreter_from_relpath(identity_str, filters=filters)
      if pi:
        yield pi
1005024
def _init_threading(self, function, params={}, num_threads=10):
        
        q = Queue(maxsize=0) # TODO: find something appropriate
        for i in range(num_threads):
            worker = Thread(target=function, args=(q, params))
            worker.setDaemon(True)
            worker.start()
        return q
337233
def _config_ini(path):
    
    conf = configparser.ConfigParser()
    conf.read(path)
    return dict(conf)
1373465
def create_init_files(path):
    
    python_files = sorted([os.path.basename(file_)[:-3] for file_ in
                           glob.glob(os.path.join(path, '*.py'))
                           if not file_.endswith('__init__.py')])

    folders = sorted([os.path.basename(folder) for folder in os.listdir(path)
                      if os.path.isdir(os.path.join(path, folder))])
    with open(path + '/__init__.py', 'w') as fn:
        if python_files:
            [fn.write('from %s import *\n' % file_) for file_ in python_files]
            [fn.write('import %s\n' % folder) for folder in folders]
    for folder in folders:
        create_init_files(os.path.join(path, folder))
97520
def get_init_args(inst_type, init_args: dict, add_kwargs=False) -> Tuple[List, Dict]:
    ''''''
    try:
        parameters = signature(inst_type).parameters.values()
        args_keys = [p.name for p in parameters \
                if p.kind in [Parameter.POSITIONAL_ONLY, Parameter.POSITIONAL_OR_KEYWORD] \
                and p.default == Parameter.empty]
        args = [init_args[key] for key in args_keys]
        kwargs = _get_var_kwargs(parameters, args_keys, init_args)\
                 if add_kwargs else\
                 _get_kwargs(parameters, init_args)
    except KeyError as key_error:
        msg_format = 'parameter with key "{0}" is not found in node args'
        raise RenderingError(msg_format.format(key_error.args[0]))
    return (args, kwargs)
1186870
def init():
        

        project = Project(os.path.abspath(os.getcwd()))
        paths_to_create = [
            project.data_dir,
            project.notebooks_dir,
            project.aux_dir,
            project.features_dir,
            project.preprocessed_data_dir,
            project.submissions_dir,
            project.trained_model_dir,
            project.temp_dir,
        ]

        for path in paths_to_create:
            os.makedirs(path, exist_ok=True)
1134672
def init(arg):
    

    answers = {'a': 1}
    if arg == 'interactive':
        input("""Hi There!
    DataFlows will now bootstrap a data processing flow based on your needs.

    Press any key to start...
    """)

    elif arg == 'hello-world':
        raise NotImplementedError()
    else:
        url = arg
        answers = dict(
            input='remote',
            title=os.path.basename(url),
            input_url=url,
            processing=[],
            output='print_n_pkg'
        )
        extract_format(answers, url)

    questions = [
        # Input
        inquirer.List('input_str',
                    message='What is the source of your data?',
                    choices=INPUTS.keys(),
                    ignore=lambda ctx: ctx.get('input') is not None,
                    validate=convert_input),

        # Input Parameters
        inquirer.Text('input_url',
                    message="What is the path of that file",
                    ignore=fany(lambda ctx: ctx.get('input') != 'file',
                                lambda ctx: ctx.get('input_url') is not None),
                    validate=fall(not_empty, extract_format)),
        inquirer.List('format',
                    message="We couldn't detect the file format - which is it?",
                    choices=FORMATS[:-1],
                    ignore=fany(lambda ctx: ctx.get('input') != 'file',
                                lambda ctx: ctx.get('format') in FORMATS)),

        inquirer.Text('input_url',
                    message="Where is that file located (URL)",
                    ignore=fany(lambda ctx: ctx.get('input') != 'remote',
                                lambda ctx: ctx.get('input_url') is not None),
                    validate=fall(extract_format, not_empty, valid_url)),
        inquirer.List('format',
                      message="We couldn't detect the source format - which is it",
                      choices=FORMATS,
                      ignore=fany(lambda ctx: ctx['input'] != 'remote',
                                  lambda ctx: ctx.get('format') in FORMATS)
                      ),
        inquirer.Text('sheet',
                      message="Which sheet in the spreadsheet should be processed (name or index)",
                      validate=not_empty,
                      ignore=lambda ctx: ctx.get('format') not in ('xls', 'xlsx', 'ods'),
                      ),
        inquirer.Text('input_url',
                      message="What is the connection string to the database",
                      validate=not_empty,
                      ignore=fany(lambda ctx: ctx['input'] != 'sql',
                                  lambda ctx: ctx.get('input_url') is not None),
                      ),
        inquirer.Text('input_db_table',
                      message="...and the name of the database table to extract",
                      validate=not_empty,
                      ignore=fany(lambda ctx: ctx['input'] != 'sql',
                                  lambda ctx: ctx.get('input_db_table') is not None),
                      ),

        inquirer.Text('input_url',
                      message="Describe that other source (shortly)",
                      ignore=fany(lambda ctx: ctx['input'] != 'other',
                                  lambda ctx: ctx.get('input_url') is not None),
                      ),

        # Processing
        inquirer.Checkbox('processing_str',
                        message="What kind of processing would you like to run on the data",
                        choices=PROCESSING.keys(),
                        ignore=lambda ctx: ctx.get('processing') is not None,
                        validate=convert_processing),

        # Output
        inquirer.List('output_str',
                    message="Finally, where would you like the output data",
                    choices=OUTPUTS.keys(),
                    ignore=lambda ctx: ctx.get('output') is not None,
                    validate=convert_output),
        inquirer.Text('output_url',
                      message="What is the connection string to the database",
                      validate=not_empty,
                      ignore=fany(lambda ctx: ctx['output'] != 'sql',
                                  lambda ctx: ctx.get('output_url') is not None),
                      ),
        inquirer.Text('output_db_table',
                      message="...and the name of the database table to write to",
                      validate=not_empty,
                      ignore=fany(lambda ctx: ctx['output'] != 'sql',
                                  lambda ctx: ctx.get('output_db_table') is not None),
                      ),

        # # Finalize
        inquirer.Text('title',
                    message="That's it! Now, just provide a title for your processing flow",
                    ignore=lambda ctx: ctx.get('title') is not None,
                    validate=not_empty),
    ]
    answers = inquirer.prompt(questions, answers=answers, theme=themes.GreenPassion())
    if answers is None:
        return
    answers['slug'] = slugify.slugify(answers['title'], separator='_')

    filename = '{slug}.py'.format(**answers)
    with open(filename, 'w') as out:
        print('Writing processing code into {}'.format(filename))
        out.write(render(answers))

    try:
        print('Running {}'.format(filename))
        ret = subprocess.check_output('python '+filename,
                                      stderr=subprocess.PIPE, universal_newlines=True, shell=True)
        print(ret)
        print('Done!')
    except subprocess.CalledProcessError as e:
        print("Processing failed, here's the error:")
        print(e.stderr)
        answers = inquirer.prompt([
            inquirer.Confirm('edit',
                            message='Would you like to open {} in the default editor?'.format(filename),
                            default=False)
        ])
        if answers['edit']:
            click.edit(filename=filename)
597528
def load_collectors_from_entry_point(path):
    
    collectors = {}
    for ep in pkg_resources.iter_entry_points(path):
        try:
            mod = ep.load()
        except Exception:
            logger.error('Failed to import entry_point: %s. %s',
                         ep.name,
                         traceback.format_exc())
        else:
            collectors.update(get_collectors_from_module(mod))
    return collectors
1175022
function initHandlers() {

    // ### `da:list-clients ()`
    //
    // List clients connected to the NodeJS message relay server.

    if(isNodeJs()) {
      da.handle('da:list-clients', () => Array.from(wsClients.keys()), {public: true});
    }

    // ### `da:get (url)`
    //
    // Get the content of a URL. This is needed by the module loader:
    // WebWorkers may not be able to load the modules due to the web security model,
    // but they can they are able to request them through the main thread.

    da.handle('da:GET', da.GET);

    // ### `da:status ()`
    //
    // Get a status with a timestamp. 
    // Can be used to ping for latency and checking whether a thread is alive.

    da.handle('da:status', () => ({pid: da.pid, time: Date.now()}), {public: true});

    // ### `da:children ()`

    if(!isBrowser()) {
      da.handle('da:children', da.children);
    }
  }
1327744
def _init_worker(X, X_shape, X_dtype):
    """"""
    # Using a dictionary is not strictly necessary. You can also
    # use global variables.
    mprotate_dict["X"] = X
    mprotate_dict["X_shape"] = X_shape
    mprotate_dict["X_dtype"] = X_dtype