本文整理汇总了Python中multiprocessing.process.Process类的典型用法代码示例。如果您正苦于以下问题:Python Process类的具体用法?Python Process怎么用?Python Process使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Process类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
def main(gcm="", rcm="", out_folder=""):
pc = None
pf = None
kwargs = {
"start_year": 1970,
"end_year": 1999,
"rcm": rcm, "gcm": gcm,
"out_folder": out_folder
}
in_folder = "data/narccap/{0}-{1}/current".format(gcm, rcm)
if os.path.isdir(in_folder):
pc = Process(target=interpolate_to_amno, args=(in_folder, ), kwargs=kwargs)
pc.start()
else:
print "{0} does not exist, ignoring the period ...".format(in_folder)
kwargs = {
"start_year": 2041,
"end_year": 2070,
"rcm": rcm, "gcm": gcm,
"out_folder": out_folder
}
in_folder = "data/narccap/{0}-{1}/future".format(gcm, rcm)
if os.path.isdir(in_folder):
pf = Process(target=interpolate_to_amno, args=(in_folder, ), kwargs=kwargs)
pf.start()
else:
print "{0} does not exist, ignoring the period ...".format(in_folder)
#do current and future climates in parallel
if pc is not None: pc.join()
if pf is not None: pf.join()
示例2: process
def process(host,port):
from multiprocessing.process import Process
p = Process(target=run, args=(host,port))
p.daemon = True
p.start()
return p
示例3: __init__
def __init__(self, fd, queue):
assert hasattr(queue, 'put')
assert hasattr(queue, 'empty')
assert callable(fd.readline)
Process.__init__(self)
self._fd = fd
self._queue = queue
示例4: service_background_jobs
def service_background_jobs(self):
logger.info('service_background_jobs')
# NOTE: paths must begin with a "/", indicating that the first part of
# the URI is a script name (which each app, i.e "reports" serves as).
# see django.core.handlers.wsgi.__init__
uri = '/' + '/'.join([SCHEMA.REPORTS_API_URI, JOB.resource_name ])
data = {
JOB.STATE: SCHEMA.VOCAB.job.state.PENDING }
kwargs = {}
logger.info('get jobs: %r', uri)
resp = self.api_client.get(
uri, data=data, **kwargs)
job_listing = self.api_client.deserialize(resp)
if API_RESULT_DATA in job_listing:
job_listing = job_listing[API_RESULT_DATA]
for job in job_listing:
logger.info('found job: %r', job)
job_id =job[JOB.ID]
logger.info('Process the job: %r', job_id)
p = Process(target=self.client_processor.service,args=(job_id,) )
# make the parent process wait:
# p.daemon = True
# if set to true, then the parent process won't wait.
logger.info('start')
p.start();
logger.info('started...')
logger.debug('servicing completed')
示例5: lookup
def lookup(self, buildingID):
from building.dummy import dummy
'''
@buildingID: int
'''
building = Building.objects.get(bid=buildingID)
print building
if building is None:
return None
if self.binstances.has_key(buildingID) is False:
ins = None
if building.bri == BUILDING_REPRESENTATION_DEBUG:
ins = dummy.DummyBif(buildingID)
elif building.bri == BUILDING_REPRESENTATION_IFC:
raise NotImplementedError, 'Missing implementation of IFC plugin'
elif building.bri == BUILDING_REPRESENTATION_REVIT:
raise NotImplementedError, 'Missing implementation of Revit plugin'
# Fire up the simulator for the building if necessary.
self.comm_queues[buildingID] = Queue()
p = Process(target=_Manager__init_simulator, args=(ins, self.comm_queues[buildingID]))
p.start()
self.binstances[buildingID] = ins
return self.binstances[buildingID]
示例6: process_input_dir
def process_input_dir(args, input_path, output_path):
patt = input_path + os.sep + "*" + args.extension
files = glob.glob(patt)
docs_num = len(files)
if docs_num > args.threads:
slice_size = docs_num / args.threads
else:
slice_size = 1
print "Threads:", args.threads
print "Documents number:", docs_num
print "Documents per thread:", slice_size
start = 0
jobs = []
for job_num in range(args.threads):
print "Initializing process", job_num
end = start + slice_size
p = Process(target=lemmatize_files, args=(files[start:end], output_path, args))
print files[start:end]
jobs.append(p)
p.start()
start += slice_size
for p in jobs:
p.join()
if (docs_num % 2) == 1:
lemmatize_files(files, output_path, args)
示例7: __init__
def __init__(self, accessLevel, eightApi):
self.accessLevel = accessLevel
self._eightApi = eightApi
pygame.init()
self.check()
thread = Process(target=self.inputHandler)
thread.start()
示例8: add_server
def add_server(self, app_name, service_name, host, port, processor, use_simple_server=True, wait=1,
use_ssl=False, ca_certs=None, cert=None, key=None):
self.sd_client.register_endpoint(app_name, service_name, host, port)
server_process = Process(target=self.__thrift_server,
args=(processor, host, port, use_simple_server, use_ssl, ca_certs, cert, key))
server_process.start()
time.sleep(wait)
self.server_processes.append(server_process)
示例9: async_file_reading
def async_file_reading(fd, callback):
"""Helper which instantiate and run an AsynchronousFileReader."""
queue = SimpleQueue()
reader = AsynchronousFileReader(fd, queue)
reader.start()
consummer = Process(target=consume_queue, args=(queue, callback))
consummer.start()
return (reader, consummer)
示例10: __init__
def __init__(self, pipe, object_class, *args, **kwargs):
Process.__init__(self)
self.object_class = object_class
self.init_args = args
self.init_kwargs = kwargs
self.pipe = pipe
self.command_queue = []
self.message_priorities = {}
示例11: __init__
def __init__(self, sem, port=2022, protocol=ProtocolEnumerator.ECHO, users={}):
Process.__init__(self, name = "SSHServer")
self.port = port
self.users = users
self.privateKeys = {}
self.publicKeys = {}
self.protocol_ = protocol
self.exitCmd = "exit"
self.messages = []
self.sem = sem
示例12: __init__
def __init__(self, **kwargs):
"""
@param init_target: unbound instance method to call at process start
@param wrap_target: unbound instance method to wrap worker function
@param term_target: unbound instance method to call at process finish
"""
self._init_target = kwargs.pop("init_target", lambda self: None).__get__(self, Process)
self._wrap_target = kwargs.pop("wrap_target", lambda self: None).__get__(self, Process)
self._term_target = kwargs.pop("term_target", lambda self: None).__get__(self, Process)
Process.__init__(self, **kwargs)
示例13: __init__
def __init__(self, event_loop = ThreadedEventLoop()):
Process.__init__(self)
self.server_pipe, self.client_pipe = Pipe()
self.server_router = Router(self.server_pipe)
self.client_router = Router(self.client_pipe)
self.srv_command_pipe = self.server_router.create()
self.cli_command_pipe = self.client_router.create(self.srv_command_pipe.id)
self.children = {}
self.client_event_loop = event_loop
self.client_event_loop.register_hook(self.client_router.eventloop_hook)
示例14: test_mcdpweb_server
def test_mcdpweb_server(dirname):
port = random.randint(11000, 15000)
base = 'http://127.0.0.1:%s' % port
p = Process(target=start_server, args=(dirname, port,))
p.start()
print('sleeping')
time.sleep(5)
try:
url_wrong = base + '/not-existing'
urllib2.urlopen(url_wrong).read()
except HTTPError:
pass
else:
raise Exception('Expected 404')
# now run the spider
tmpdir = tempfile.mkdtemp(prefix='wget-output')
cwd = '.'
cmd = ['wget', '-nv', '-P', tmpdir, '-m', base]
# res = system_cmd_result(
# cwd, cmd,
# display_stdout=True,
# display_stderr=True,
# raise_on_error=True)
sub = subprocess.Popen(
cmd,
bufsize=0,
cwd=cwd)
sub.wait()
exc = get_exceptions(port)
if len(exc) == 0:
msg = 'Expected at least a not-found error'
raise Exception(msg)
if not 'not-existing' in exc[0]:
raise Exception('Could not find 404 error')
exc = exc[1:]
if exc:
msg = 'Execution raised errors:\n\n'
msg += str("\n---\n".join(exc))
raise_desc(Exception, msg)
url_exit = base + '/exit'
urllib2.urlopen(url_exit).read()
print('waiting for start_server() process to exit...')
p.join()
print('...clean exit')
示例15: __new__
def __new__(self, type_, tId, qDistributor, q, model):
if type_==SolverImplType.THREADED:
thread = threading.Thread(target=SolverWorker, args=[tId, q, qDistributor, model])
thread.setName("LoopingSolver_thread_%(I)s"%{"I":tId})
thread.setDaemon(True)
elif type_==SolverImplType.MULTIPROCESSOR:
thread = Process(target=SolverWorker, args=[tId, q, qDistributor, model])
thread.setName("LoopingSolver_process_%(I)s"%{"I":tId})
thread.setDaemon(True)
else:
raise TypeError("Unknown SolverImplType: '%(T)s'."%{"T":type_})
return thread