0

I am using tftpy and need to create a server, then a client to download/upload some file and then I can close the server.

I was thinking on using multiprocessing to accomplish this but I don't know how to close the server gracefully. The last resort will be to use terminate() but perhaps there is a better method (perhaps an easier one not using multiprocessing). I also know about multiprocessing.Event() but I don't know how run_sv() method will keep listening

Here is the code:

import multiprocessing
import tftpy

def run_sv():
    name = multiprocessing.current_process().name
    print name, 'Starting sv'
    server = tftpy.TftpServer('./rootf')
    server.listen('0.0.0.0', 69)
    print name, 'Exiting sv'

def run_cl():
    name = multiprocessing.current_process().name
    print name, 'Starting cl'
    client = tftpy.TftpClient('127.0.0.1', 69)
    client.download('aaa.txt', './downf/zzz.txt')
    print name, 'Exiting cl'

if __name__ == '__main__':
    service = multiprocessing.Process(name='my_sv', target=run_sv)
    worker_1 = multiprocessing.Process(name='my_cl', target=run_cl)

    service.start()
    worker_1.start()

The output:

my_sv Starting sv
my_cl Starting cl
my_cl Exiting cl

and of course it hangs there.

4

1 回答 1

1

Try this:

service.start()
worker_1.start()
worker_1.join()
service.terminate()
于 2013-07-23T16:23:24.793 回答