Skip to content

Commit 938ff62

Browse files
committed
multiprocess
1 parent f2ecf05 commit 938ff62

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

mytest.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ def delete(list):
5353

5454

5555
class A:
56+
def __init__(self):
57+
print('A__init__')
58+
5659
def serve_forever(self):
5760
self.A()
5861

@@ -61,15 +64,22 @@ def A(self):
6164

6265

6366
class B(A):
64-
pass
67+
def __init__(self):
68+
print('B__init__ run')
6569

6670

6771
class C:
72+
def __init__(self):
73+
print('C__init__ run')
74+
6875
def A(self):
6976
print('CCC')
7077

7178

7279
class D(C, B):
80+
def __init__(self):
81+
C.__init__(self)
82+
B.__init__(self)
7383
pass
7484

7585

studyLib/process_thread/multi_thread.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
# -*- coding: utf-8 -*-
33

44
from threading import Thread
5+
import multiprocessing
56
import time
67

78
__author__ = 'Mr.Huo'
@@ -15,6 +16,7 @@ def counter():
1516

1617

1718
def main():
19+
# GIL的存在,多线程并不能正真的实现并发
1820
thread_array = {}
1921
start_time = time.time()
2022
for tid in range(2):
@@ -28,6 +30,16 @@ def main():
2830
end_time = time.time()
2931
print("Total time: {}".format(end_time - start_time))
3032

33+
# 多进程
34+
mp = multiprocessing.Pool()
35+
mp_start = time.time()
36+
for i in range(2):
37+
mp.apply_async(counter)
38+
mp.close()
39+
mp.join()
40+
mp_end = time.time()
41+
print("Total time: {}".format(mp_end - mp_start))
42+
3143

3244
if __name__ == '__main__':
3345
main()

studyLib/socket/__init__.py

Lines changed: 0 additions & 13 deletions
This file was deleted.

0 commit comments

Comments
 (0)