Skip to content

Commit 6acf7d2

Browse files
AdministratorAdministrator
Administrator
authored and
Administrator
committed
threading
1 parent 1345d03 commit 6acf7d2

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

src/main/python/demo_child_process.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#print(p.returncode)
1616

1717

18-
p = subprocess.run("tasklist", shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
18+
p = subprocess.run("tasklist", shell=True, capture_output=True)
1919

2020
if p.stdout:
2121
print(p.stdout)
+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env python3
2+
3+
import threading
4+
import time
5+
6+
7+
def cycle_race(*args):
8+
cyclist = args[0]
9+
handicap = args[1]
10+
11+
for distance in range(0, 1001, 100):
12+
print(f"{cyclist} - {distance}m")
13+
time.sleep(handicap)
14+
return
15+
16+
print("Starting cycle race.")
17+
18+
t1 = threading.Thread(target=cycle_race, args=('david', 1.345))
19+
t2 = threading.Thread(target=cycle_race, args=('conny', 1.567))
20+
21+
t1.start()
22+
t2.start()
23+
24+
t1.join()
25+
t2.join()
26+
27+
28+
print("Race finished.")

src/main/python/demo_threading.py

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/usr/bin/env python3
2+
3+
import threading
4+
import time
5+
6+
7+
def cycle_race(*args):
8+
cyclist = args[0]
9+
handicap = args[1]
10+
11+
for distance in range(0, 1001, 100):
12+
print(f"{cyclist} - {distance}m")
13+
time.sleep(handicap)
14+
return
15+
16+
17+
print("Starting cycle race.")
18+
19+
cycle_race('david', 1.345)
20+
cycle_race('conny', 1.567)
21+
22+
print("Race finished.")

0 commit comments

Comments
 (0)