-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththreadingTest.py
More file actions
38 lines (33 loc) · 814 Bytes
/
threadingTest.py
File metadata and controls
38 lines (33 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import threading;
import time;
import scrapy;
from docutils.nodes import thead
import lxml;
sem = threading.Semaphore(value=1);
is_start = threading.Event();
def run():
global chen,is_start;
# sem.acquire();
print(threading.current_thread().getName());
print("before add "+ str(chen))
# time.sleep(0.2);
chen = chen+1;
print("after add "+ str(chen))
# time.sleep(0.2);
chen = chen - 1;
print("before jian "+ str(chen))
time.sleep(5);
is_start.set();
# sem.release();
def run1():
global is_start;
if is_start.isSet()==False:
is_start.wait();
print(is_start.isSet());
print("begin");
if(__name__=="__main__"):
chen = 0;
t = threading.Thread(target=run);
t1 = threading.Thread(target=run1);
t.start();
t1.start();