Pyinstaller编译的python 3.5.4,内置print()语句抛出OSError:[Erno 22]无效参



我有一个program.exe文件,它是用pyinstaller3.5版通过运行命令pyinstaller --log-level DEBUG program.py编译的。program.py包括几个print(string_variables)语句。

# The codes below run 3 times per second, as it keeps receiving image data using a socket of TCP protocol.
log_text(time_now() + "Sent " + connCmd, log_to_disk=False)
# ...
log_text(time_now() + "Written to cur_image.jpg", log_to_disk=False)
# ...
# project01logger.py
def log_text(self, text, log_to_disk=True):
log_text = time_now() + str(text)
try:
print(log_text)
except:
self.log_to_txt(format_exc())
self.log_to_txt("Print statement raised error while printing '" + log_text + "'")
if log_to_disk:
self.log_to_txt(log_text)
def log_to_txt(self, content):
try:
with open(self.log_path, "a") as f:
f.write(content + "n")
except Exception as e:
# ... not shown as no exception has ever been caught here.

错误如下:

Traceback (most recent call last):
File "project01logger.py", line 36, in log_text
OSError: [Errno 22] Invalid argument
Print statement raised error while printing '09/03/2020 09:22:28: Took 2 loops to receive the current image.'
09/03/2020 09:22:37: Received a TCP command signal.
09/03/2020 09:22:43: Received a TCP command signal
Traceback (most recent call last):
File "project01logger.py", line 36, in log_text
OSError: [Errno 22] Invalid argument
Print statement raised error while printing '09/03/2020 09:22:45: Written to cur_image.jpg'
Traceback (most recent call last):
File "project01logger.py", line 36, in log_text
OSError: [Errno 22] Invalid argument
Print statement raised error while printing '09/03/2020 09:22:59: Sent BBBB'

相同的OSError: [Errno 22] Invalid argument大约每20秒发生一次,这种情况持续了几个小时,然后在接下来的几个小时内再也不会发生,然后在几个小时内再次发生,以此类推

我甚至找不到让print((语句抛出OSError: [Errno 22] Invalid argument的方法。这不可能是因为传递到print()中的任何字符串变量,对吧?因为所有这些都可以记录到磁盘上。知道是什么导致了这个错误吗?

尝试添加绝对路径而不是相对路径:

/home/用户名/文件夹/project01/logger.py

在ubuntu添加绝对路径工作,在windows中,我有同样的问题

最新更新