python get all file descriptor opening with socket -


i use flask , flask's internal web server on unix based os. run like;

app.run(host='', port=8000, threaded=true, debug=false) 

i restart serivces in code like

  service in active_services:         command = "/etc/init.d/%s restart" % service         # stdout , stderr string output of command         stdout, stderr = popen(command, stdout=pipe, stderr=pipe,shell=true).communicate() 

when stop flask app, other services ,which restart, start listen 8000 port. caused file descriptors opening flask inherited subprocess. prevent problem try reach file descriptors of socket. how can that?

for solving problem, gc can used getting creating object. after create , bind socket, can run code , socketobjects;

for sock in filter(lambda x: type(x) == socket._socketobject, gc.get_objects()):     fd = sock.fileno()     old_flags = fcntl.fcntl(fd, fcntl.f_getfd)     fcntl.fcntl(fd, fcntl.f_setfd, old_flags | fcntl.fd_cloexec) 

this code prevent inheritance of sockets' file descriptor.


Comments

Popular posts from this blog

how to proxy from https to http with lighttpd -

android - Automated my builds -

python - Flask migration error -