Skip to content

Commit 96cdecd

Browse files
committed
rebuild project 2018年 03月 26日 星期一 21:06:33 CST
1 parent 3d960a7 commit 96cdecd

File tree

8 files changed

+66
-0
lines changed

8 files changed

+66
-0
lines changed

python/Raspberry-Pi-Gas-Sensor-MQ

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Subproject commit 5840e2642127f2d75ccdf527ec2997c633bd33e2

python/pratice/io1.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
f = open('./temp.txt','r')
2+
for line in f.readlines():
3+
print(line.strip())
4+

python/pratice/io2.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
fpath = r'C:\Windows\System32\xinput1_1.dll'
2+
with open(fpath,'r') as f:
3+
s=f.read()
4+
print(s)

python/pratice/io3.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from io import StringIO
2+
f = StringIO("Hello!\nHi!\nYHY!")
3+
4+
5+
for s in f.readlines():
6+
print(s.strip())

python/pratice/lock.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import time,threading
2+
3+
balance = 0
4+
lock = threading.Lock()
5+
def change_it(n):
6+
global balance
7+
balance = balance+n
8+
balance = balance-n
9+
10+
def run_thread(n):
11+
for i in range(1000000):
12+
lock.acquire()
13+
try:
14+
change_it(n)
15+
finally:
16+
lock.release()
17+
t1 = threading.Thread(target=run_thread,args=(5,))
18+
t2 = threading.Thread(target=run_thread,args=(9,))
19+
20+
t1.start()
21+
t2.start()
22+
t1.join()
23+
t2.join()
24+
print(balance)

python/pratice/process.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import os
2+
print('Process(%s)start' % os.getpid())
3+
pid = os.fork()
4+
if pid==0:
5+
print('I am child process(%s)and my parent is%s' %(os.getpid(),os.getppid()))
6+
else:
7+
print('I (%s) just created a child process (%s)'%(os.getpid(),pid))
8+

python/pratice/temp.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
11
i love yhy
2+
i love yhy
3+
i love yhy
4+
i love yhy

python/pratice/thread1.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import time,threading
2+
def loop():
3+
print('thread %s is running...'% threading.current_thread().name)
4+
n=0
5+
while n<5:
6+
n=n+1
7+
print('thread %s >>> %s'%(threading.current_thread().name,n))
8+
time.sleep(1)
9+
print('thread %s ended'%threading.current_thread().name)
10+
11+
print('thread %s is running..'%threading.current_thread().name)
12+
t = threading.Thread(target=loop,name='LoopThread')
13+
t.start()
14+
t.join()
15+
print('thread %s ended'%threading.current_thread().name)
16+

0 commit comments

Comments
 (0)