[INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 46.000 s (Wall Clock) [INFO] Finished at: 2019-02-10T11:28:39+08:00 [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal on project spark-launcher_2.11: Could not resolve dependencies for project org.apache.spark:spark-launcher_2.11:jar:2.2.3: Could not find artifact org.apache.hadoop:hadoop-client:jar:2.6.0-cdh5.7.0 in alimaven (http://maven.aliyun.com/nexus/content/groups/public/) -> [Help 1]
Using Spark's default log4j profile: org/apache/spark/log4j-defaults.properties Setting default log level to "WARN". To adjust logging level use sc.setLogLevel(newLevel). For SparkR, use setLogLevel(newLevel). 19/02/10 12:13:43 WARN Utils: Your hostname, localhost resolves to a loopback address: 127.0.0.1; using 192.168.1.6 instead (on interface en0) 19/02/10 12:13:43 WARN Utils: Set SPARK_LOCAL_IP if you need to bind to another address 19/02/10 12:13:43 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable Spark context Web UI available at http://192.168.1.6:4040 Spark context available as 'sc' (master = local[*], app id = local-1549772024897). Spark session available as 'spark'. Welcome to ____ __ / __/__ ___ _____/ /__ _\ \/ _ \/ _ `/ __/ '_/ /___/ .__/\_,_/_/ /_/\_\ version 2.2.3 /_/
Using Scala version 2.11.8 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_181) Type in expressions to have them evaluated. Type :help for more information.
print('Process (%s) starts...' % os.getpid()) # Only works on Unix / Linux / Mac: pid = os.fork() if pid == 0: print('I am a child process (%s) and my parent is (%s).' % (os.getpid(), os.getppid())) else: print('I (%s) just created a child process (%s).' % (os.getpid(), pid))
运行结果如下:
1 2 3
Process (56351) starts... I (56351) just created a child process (56352). I am a child process (56352) and my parent is (56351).
from multiprocessing import Process import os import time
# 子进程要执行的代码 defrun_proc(name): print('Run child process %s (%s)' % (name, os.getpid())) time.sleep(2) print('Child process ends')
if __name__ == '__main__': print('Parent process %s.' % os.getpid()) p = Process(target=run_proc, args=('test',)) print('Child process will start.') p.start() p.join() print('Parent process end.')
执行结果如下:
1 2 3 4 5
Parent process 56782. Child process will start. Run child process test (56783) Child process ends Parent process end.
if __name__=='__main__': print('Parent process %s.' % os.getpid()) p = Pool(4) for i inrange(5): p.apply_async(long_time_task, args=(i,)) print('Waiting for all subprocesses done...') p.close() p.join() print('All subprocesses done.')
执行结果如下:
1 2 3 4 5 6 7 8 9 10 11 12 13
Parent process 57316. Waiting forall subprocesses done... Run task 0 (57317)... Run task 1 (57318)... Run task 2 (57319)... Run task 3 (57320)... Task 0 runs 0.59 seconds. Run task 4 (57317)... Task 4 runs 1.06 seconds. Task 3 runs 1.96 seconds. Task 1 runs 2.02 seconds. Task 2 runs 2.99 seconds. All subprocesses done.
对Pool对象调用join()方法会等待所有子进程执行完毕,调用join()之前必须先调用close(),不然会出现ValueError: Pool is still running错误。调用close()之后就不能继续添加新的Process了。
Non-authoritative answer: python.org mail exchanger = 50 mail.python.org.
Authoritative answers can be found from: mail.python.org internet address = 82.94.164.166 mail.python.org has AAAA address 2001:888:2000:d::a6 Exit code: 0
from multiprocessing import Process, Queue import os, time, random
# 写数据进程执行的代码: defwrite(q): print('Process to write: %s' % os.getpid()) for value in ['A', 'B', 'C']: print('Put %s to queue...' % value) q.put(value) time.sleep(random.random())
# 读数据进程执行的代码: defread(q): print('Process to read: %s' % os.getpid()) whileTrue: value = q.get(True) print('Get %s from queue.' % value)
Process to write: 50563 Put A to queue... Process to read: 50564 Get A from queue. Put B to queue... Get B from queue. Put C to queue... Get C from queue.