Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 54cd3bf

Browse files
learning the very basic syntax
0 parents commit 54cd3bf

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

‎Processes/one.py‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import multiprocessing
2+
3+
def calc_power(base, power):
4+
print('Number: ', base)
5+
result = base**power
6+
print('Result: ', result)
7+
8+
if __name__ == '__main__':
9+
result = 0
10+
p1 = multiprocessing.Process(target=calc_power, args=(7, 2))
11+
p2 = multiprocessing.Process(target=calc_power, args=(11, 4))
12+
13+
p1.start()
14+
p2.start()
15+
16+
p1.join()
17+
p2.join()
18+
19+
print('result is: ', result)

‎README.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Python Multithreadig and Multiprocessing
2+
3+
here are the resources I used:
4+
<ul>
5+
<li>https://dev.to/nbosco/multithreading-vs-multiprocessing-in-python--63j</li>
6+
</ul>

‎Threads/one.py‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import threading
2+
3+
def calc_power(base, power):
4+
print(base**power)
5+
6+
if __name__ == '__main__':
7+
number = 7
8+
thread1 = threading.Thread(target=calc_power, args=(number, 2))
9+
thread2 = threading.Thread(target=calc_power, args=(number, 4))
10+
11+
thread1.start()
12+
thread2.start()
13+
14+
thread1.join()
15+
thread2.join()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /