code: def run_impl(
      strategyClass,
      barFeed,
      strategyParameters,
      batchSize,
      workerCount=None,
      logLevel=logging.ERROR,
      resultSinc=None,
  ):
      if workerCount is None:
          workerCount = multiprocessing.cpu_count()
      assert workerCount > 0, "No workers"
  
      ret = None
      workers = []
      port = find_port()
      if port is None:
          raise Exception("Failed to find a port to listen")
  
      # Build and start the server thread before the worker processes.
      # We'll manually stop the server once workers have finished.
      paramSource = base.ParameterSource(strategyParameters)
      if resultSinc is None:
          resultSinc = base.ResultSinc()
  
      # Create and start the server.
      logger.info("Starting server on port %s" % port)
      srv = xmlrpcserver.Server(
          paramSource,
          resultSinc,
          barFeed,
          "localhost",
          port,
          autoStop=False,
          batchSize=batchSize,
      )
      serverThread = ServerThread(srv)
      serverThread.start()
      logger.info("Waiting for the server to be ready")
      srv.waitServing()
  
      try:
          logger.info("Starting %s workers" % workerCount)
          # Build the worker processes.
          for i in range(workerCount):
              workers.append(
                  multiprocessing.Process(
                      target=worker_process,
                      args=(strategyClass, port, logLevel),
                  )
              )
          # Start workers
          for process in workers:
              process.start()
  
          # Wait for all jobs to complete.
          while srv.jobsPending():
              time.sleep(1)
      finally:
          # Stop workers
          for process in workers:
              stop_process(process)
  
          # Stop and wait the server to finish.
          logger.info("Stopping server")
          srv.stop()
          serverThread.join()
  
          bestResult, bestParameters = resultSinc.getBest()
          if bestResult is not None:
              ret = server.Results(bestParameters.args, bestResult)
  
      return ret
  
file_path: pyalgotrade/pyalgotrade/optimizer/local.py
imports: import logging
  import multiprocessing
  import os
  import random
  import socket
  import threading
  import time
  from pyalgotrade.optimizer import base
  from pyalgotrade.optimizer import server
  from pyalgotrade.optimizer import worker
  from pyalgotrade.optimizer import xmlrpcserver
label_desc: Use image node_id 4 for calling a global function with example usage: run_impl(strategyClass, barFeed, strategyParameters, batchSize, workerCount, logLevel, resultSinc) and returns: ret