close failed in file object destructor: IOError: [Error 10] No child processes

this problem is really annoying, it took me half a day to solve. It turns out that the reason is a small problem, but it is usually ignored, looking for a long time on the Internet seems to be different from my situation

is timed to query the current port concurrency every 30 seconds and record it in the document

import os
from threading import Thread

def check_count():
def check_count():
MSG = os.popen(‘ netstat -nat |grep 9995 | wc-l ‘)
count = msg.read()
current_time = datetime. Datetime. Now (). Strftime (“%Y-%m-%d %H:% m :%S”)
with Open (‘ /home/opvis/transfer_server/log/ check_port.log ‘, ‘a’) as f:
f.write(current_time + ‘, current time concurrent visits are: ‘+ count)
time.sleep(30)
t= Thread(target=check_count)
t.daemon (True)
t.daemon ()

results will run normally, but at the terminal will always report the following error :

because the last os.popen execution object was not closed. The next time the loop executes os.popen, the error will appear
.

will no longer be displayed

def check_count():
def check_count():
MSG = os.popen(‘ netstat -nat |grep 9995 | wc-l ‘)
count = msg.read()
current_time = datetime. Datetime. Now (). Strftime (“%Y-%m-%d %H:% m :%S”)
with Open (‘ /home/opvis/transfer_server/log/ check_port.log ‘, ‘a’) as f:
f.write(current_time + ‘, current time concurrent visits are: ‘+ count)
MSG. Close ()
time.sleep(30)
t= Thread(target=check_count)
t.daemon (True)
t.daemon ()

Read More: