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.

3
  • tried calling .close() on server before the end of run_sv? Commented Jul 23, 2013 at 16:20
  • servers do tend to run indefinitely, you should find a way how to shuit it down after the client has done its work Commented Jul 23, 2013 at 16:21
  • no close() method. the server starts to listen and doesn't give the "promt" back. Terminating the process pid with terminate() is an alternative but is not graceful. Commented Jul 23, 2013 at 16:23

1 Answer 1

1

Try this:

service.start()
worker_1.start()
worker_1.join()
service.terminate()
Sign up to request clarification or add additional context in comments.

2 Comments

Did it hang in the main process at the waiting for the client or for the server that time?
import tftpy client = tftpy.TftpClient('192.168.0.42', 69, options={'blksize': 8});client.download('breed.bin','output.bin') TftpException: Invalid options in buffer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.