使用我的多处理代码
def __get_courses_per_moderator(self, moderator, page=None):
print("started")
try:
response = self.class_service.courses().list(pageSize=0,
courseStates='ACTIVE',
teacherId=moderator, pageToken=None).execute()
for data in response["courses"]:
self.courses_in_classroom.append(data["name"])
print(self.courses_in_classroom) # THE modifications are clear
except Exception as e:
print("__get_courses_per_moderator ERROR-{}".format(e))
def get_courses_from_classroom(self):
# batch = service.new_batch_http_request(callback=self.__callback)
pool = []
for email in self.additional_emails:
try:
process = multiprocessing.Process(
target=self.__get_courses_per_moderator, args=[email])
process.start()
pool.append(process)
except Exception as e:
print("get_courses_from_classroom ERROR-{}".format(e))
for process in pool:
process.join()
print("joined")
print(self.courses_in_classroom) # the attribute is empty.
据我了解python是同步的。那么当进程更新类属性时,值应该在那里吗?还是我应该尝试返回它,然后在 join() 之后连接?一个简单的解释会很可爱。