Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux Python脚本在/tmp/中创建目录,占用系统空间_Linux_Python 3.x_Filesystems_Tmp - Fatal编程技术网

Linux Python脚本在/tmp/中创建目录,占用系统空间

Linux Python脚本在/tmp/中创建目录,占用系统空间,linux,python-3.x,filesystems,tmp,Linux,Python 3.x,Filesystems,Tmp,我运行的脚本充当服务器,允许两个客户端连接到它,对于一个特定的客户端向服务器发送消息,服务器修改它,然后将它发送到另一个客户端 这似乎是可行的,因为接收客户端确认输入已收到且有效。这是一个我打算持续运行的脚本 然而,一个大问题是,我的/tmp/目录中充满了名为\u M…(省略号表示一个随机字符串)的目录,其中包含python模块(例如,据我所知,我没有使用的加密)和时区信息(实际上python支持的每个时区)。它似乎非常频繁地创建它们,但我无法确定过程中到底是什么在这样做 我已经创建了一个工作清

我运行的脚本充当服务器,允许两个客户端连接到它,对于一个特定的客户端向服务器发送消息,服务器修改它,然后将它发送到另一个客户端

这似乎是可行的,因为接收客户端确认输入已收到且有效。这是一个我打算持续运行的脚本

然而,一个大问题是,我的/tmp/目录中充满了名为
\u M…
(省略号表示一个随机字符串)的目录,其中包含python模块(例如,据我所知,我没有使用的加密)和时区信息(实际上python支持的每个时区)。它似乎非常频繁地创建它们,但我无法确定过程中到底是什么在这样做

我已经创建了一个工作清理bash脚本,该脚本每5分钟从目录中删除超过5分钟的文件,但是,我不能保证在为其他设备复制此过程时,目录将具有相同的名称格式。与其为我创建的每个进程创建一个唯一的bash脚本,我更希望能够从python脚本中清理目录,甚至更好,以防止目录被创建

问题是,我不确定这是如何实现的,我也没有看到任何关于创建这些目录的内容,也没有看到如何删除这些目录的内容

下面是我的脚本

import time, socket, os, sys, re, select

IP = '192.168.109.8'
PORT = [3000, 3001]
PID = str(os.getpid())
PIDFILE = "/path/to/pidfile.pid"
client_counter = 0
sockets_list = []

def runCheck():
    if os.path.isfile(PIDFILE):
        return False
    else:
        with open(PIDFILE, 'w') as pidfile:
            pidfile.write(PID)
        return True

def openSockets():
    for i in PORT:
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
        s.bind((IP, i))
        s.listen(1)
        sockets_list.append(s)

def receiveMessage(client_socket):
    try:
        message = client_socket.recv(2048).decode('utf-8')
        if not message:
            return False
        message = str(message)
        return message
    except:
        return False

def fixString(local_string):
    #processes
    return local_string

def main():
    try:
        openSockets()
        clients = {}
        print(f'Listening for connections on {IP}:{PORT[0]} and {PORT[1]}...')
        client_count = 0

        while True:
            read_sockets, _, exception_sockets = select.select(sockets_list, [], sockets_list)
            for notified_socket in read_sockets:
                if notified_socket == sockets_list[0] or notified_socket == sockets_list[1]:
                    client_socket, client_address = sockets_list[client_count].accept()
                    client_count = (client_count + 1) % 2
                    sockets_list.append(client_socket)
                    clients[client_socket] = client_socket
                    print('Accepted new connection from: {}'.format(*client_address))
                else:
                    message = receiveMessage(notified_socket)
                    if message is False:
                        continue

                    message = fixString(message)

                    for client_socket in clients:
                        if client_socket != notified_socket:
                            if message != "N/A":
                                client_socket.send(bytes(message, "utf-8"))
            for notified_socket in exception_sockets:
                sockets_list.remove(notified_socket)
                del clients[notified_socket]
            time.sleep(1)

    except socket.timeout:
        for i in sockets_list:
            i.close()
        os.remove(PIDFILE)
        sys.exit()
    except Exception as e:
        for i in sockets_list:
            i.close()
        err_details = str('Error in line {}'.format(sys.exc_info()[-1].tb_lineno), type(e).__name__, e)
        os.remove(PIDFILE)
        print("Exception: {}".format(err_details))
        sys.exit()

if __name__ == "__main__":
    if runCheck():
        main()
    else:
        pass

我应该如何设置它,以便python脚本删除它在/tmp/目录中创建的目录,或者更好,一开始就不创建它们?任何帮助都将不胜感激。

事实证明,是PyInstaller生成了这些文件。在文档中,它指出pyinstaller在以单文件模式创建可执行文件时生成了这个
\u MEI
目录,并且它也应该删除它,但由于某些原因它没有删除。

事实证明,是pyinstaller生成了这些文件。在文档中,它声明pyinstaller在以单文件模式创建可执行文件时生成此
\u-MEI
目录,并且它也应该删除它,但由于某些原因它没有删除