def run(): # make sure that we run the reactor with the sentinel log context, # otherwise other PreserveLoggingContext instances will get confused # and complain when they see the logcontext arbitrarily swapping # between the sentinel and `run` logcontexts. with PreserveLoggingContext(): logger.info("Running") if cpu_affinity is not None: # Turn the bitmask into bits, reverse it so we go from 0 up mask_to_bits = bin(cpu_affinity)[2:][::-1] cpus = [] cpu_num = 0 for i in mask_to_bits: if i == "1": cpus.append(cpu_num) cpu_num += 1 p = psutil.Process() p.cpu_affinity(cpus) change_resource_limit(soft_file_limit) if gc_thresholds: gc.set_threshold(*gc_thresholds) reactor.run()
def resolveHostName( self, resolutionReceiver, hostName, portNumber=0, addressTypes=None, transportSemantics="TCP", ): # We need this function to return `resolutionReceiver` so we do all the # actual logic involving deferreds in a separate function. # even though this is happening within the depths of twisted, we need to drop # our logcontext before starting _resolve, otherwise: (a) _resolve will drop # the logcontext if it returns an incomplete deferred; (b) _resolve will # call the resolutionReceiver *with* a logcontext, which it won't be expecting. with PreserveLoggingContext(): self._resolve( resolutionReceiver, hostName, portNumber, addressTypes, transportSemantics, ) return resolutionReceiver
def run(): # make sure that we run the reactor with the sentinel log context, # otherwise other PreserveLoggingContext instances will get confused # and complain when they see the logcontext arbitrarily swapping # between the sentinel and `run` logcontexts. with PreserveLoggingContext(): logger.info("Running") change_resource_limit(soft_file_limit) if gc_thresholds: gc.set_threshold(*gc_thresholds) reactor.run()
def notify_new_events(self, current_id): """This gets called when we have some new events we might want to send out to other servers. """ self._last_poked_id = max(current_id, self._last_poked_id) if self._is_processing: return # fire off a processing loop in the background. It's likely it will # outlast the current request, so run it in the sentinel logcontext. with PreserveLoggingContext(): self._process_event_queue_loop()
def run(): # make sure that we run the reactor with the sentinel log context, # otherwise other PreserveLoggingContext instances will get confused # and complain when they see the logcontext arbitrarily swapping # between the sentinel and `run` logcontexts. with PreserveLoggingContext(): logger.info("Running") if cpu_affinity is not None: if not affinity: quit_with_error( "Missing package 'affinity' required for cpu_affinity\n" "option\n\n" "Install by running:\n\n" " pip install affinity\n\n") logger.info("Setting CPU affinity to %s" % cpu_affinity) affinity.set_process_affinity_mask(0, cpu_affinity) change_resource_limit(soft_file_limit) if gc_thresholds: gc.set_threshold(*gc_thresholds) reactor.run()