-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththread_queues.py
More file actions
43 lines (32 loc) · 1.13 KB
/
thread_queues.py
File metadata and controls
43 lines (32 loc) · 1.13 KB
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
39
40
41
42
43
import threading
import Queue
import time
class workerThread(threading.Thread):
def __init__(self, queue):
threading.Thread.__init__(self)
self.queue = queue
def run(self):
print "In worker thread"
while True:
counter = self.queue.get()
print "Order to sleep for %d seconds" %counter
time.sleep(counter)
print "Finished sleeping for %d seconds" %counter
self.queue.task_done()
queue = Queue.Queue()
for i in range(10):
print "creating workerThread : %d" %i
worker = workerThread(queue)
worker.setDaemon(True)
worker.start()
print "WorkerThread %d created" %i
for j in range(10):
queue.put(j)
queue.join()
print "All task over !!"
#Exercise
# Create a list of FTP sites
#Create a worker thread and queues which can login to these sites and list the root directory and exit
#Use 5 threads for this job and 10 ftp sites
#Write python script showing how you can create locking mechanism with the shared resources using the thread module
#Investigate about multiprocessing module and write a TCP SYN scanner using multiprocessing