Home > other >  FTP download queue for help
FTP download queue for help

Time:11-24

Four FTP server, each server allows only 5 devices login, now has 50 sets of equipment from the server to download file
Current problem:
1) choose a FTP server code can be optimized,
2) how to in the cumulative link up to 20, let the cycle stop, wait for 20 equipment is complete, if there is a complete equipment, let the accumulative reset, continue to connect to the FTP server, accumulative total to 20 device, pause, again until 50 apparatus are finished downloading (in the queue? Behind the code does not write)

The devs=[' dev1,......, 'dev50]
The servers=[' ser1 ', 'ser2', 'ser3', 'ser4]
Connect_count=0
For dev in des:
# according to the current total number choose corresponding server
If connect_count & lt;=5:
Ftp_ser=the servers [0]
Elseif connect_count & gt; 5 and connect_count & lt;=10:
Ftp_ser=the servers [1]
Elseif connect_count & gt; 10 and connect_count & lt;=15:
Ftp_ser=the servers [2]
Elseif connect_count & gt; 15 and connect_count & lt;=20:
Ftp_ser=the servers [3]

# assumes that the equipment successfully connect FTP server
Connect_count +=1

CodePudding user response:

After baidu oneself understand

Principle is: opening 20 thread, each thread will be removed from the queue a parameter and then do the corresponding operation, operation again after check there are no parameters in the queue, so go ahead, if not quit thread,
Simple point is: the queue inside full of customers, I also opened 20 counter (threading) to deal with customer demand, after 1 counter to handle a customer, if there are customers waiting to continue processing, if not closed, the counter until all of the customers are processed,

The import queue
The import threading, time

Def rest (que) :
While not que. Empty () :
Q_name=que. The get ()
Print (q_name + '& gt; Sleep for 20 seconds. ')
Time. Sleep (20)
Print (q_name + '& gt; Wake up. ')

Q=queue. The queue ()
For I in range (1, 31) :
Q.p ut (' dev % d % I)

Max_thread=20
Ts=[]
For I in range (max_thread) :
T=threading. Thread (target=rest, args=(q,))
T.s tart ()
Ts. Append (t)
For t in ts:
T.j oin ()
  • Related