Cache the session right after they start. Related to #68

@EriHoss is right, the session can know how to clean itself in
case for some reason it fails to start, hence it makes much more
sense to cache sessions right after they start. Also, clear the
media_sessions dict when stopping to get rid of closed sessions.
This commit is contained in:
Dan 2018-05-01 21:08:47 +02:00
parent 1dc43064fb
commit f29b8bb7e4

View File

@ -423,6 +423,8 @@ class Client:
for i in self.media_sessions.values():
i.stop()
self.media_sessions.clear()
self.is_started = False
self.session.stop()
@ -2992,10 +2994,10 @@ class Client:
self.api_id
)
self.media_sessions[dc_id] = session
session.start()
self.media_sessions[dc_id] = session
session.send(
functions.auth.ImportAuthorization(
id=exported_auth.id,
@ -3011,10 +3013,10 @@ class Client:
self.api_id
)
self.media_sessions[dc_id] = session
session.start()
self.media_sessions[dc_id] = session
if volume_id: # Photos are accessed by volume_id, local_id, secret
location = types.InputFileLocation(
volume_id=volume_id,
@ -3082,10 +3084,10 @@ class Client:
is_cdn=True
)
self.media_sessions[r.dc_id] = cdn_session
cdn_session.start()
self.media_sessions[r.dc_id] = cdn_session
try:
with tempfile.NamedTemporaryFile("wb", delete=False) as f:
file_name = f.name