我有一个大问题,三天内我自己都无法解决。我们有一个应用程序,可以创建 Json 文件并通过 Boto3 库将它们发送到 Amazon S3 服务器。该应用程序是在 Python 3.8 上开发的,没有任何问题。然后Python升级到3.9+,问题就出现了。我们需要在这个应用程序中使用线程,因此我们为其创建了一个新类:
class NewThread(Thread):
def __init__(self, name):
Thread.__init__(self)
self.name = name
def run(self):
global i, listings
if self.name=='control':
# here is control-thread. Code removed for this example
while True:
time.sleep(10)
else:
i += 1
print(f'Thread {self.name} works on {files[i]}')
try:
create_file(files[i])
move_file(c.root+f'json/{files[i].replace(".", "-")}.json', 's3folder')
except Exception as e:
get_exception(e)
Run Code Online (Sandbox Code Playgroud)
函数create_file()又长又无聊。它创建一个大小为 20-25kb 的 json 文件,并且在其中没有使用任何困难。然后,必须使用函数将文件移动到 S3 move_file()。这是代码:
# Function for moving files to s3 bucket
def move_file(file, path, bucket=c.s3cfg['bucket'], …Run Code Online (Sandbox Code Playgroud)