Skip to content

Commit

Permalink
Cache the session right after they start. Related to #68
Browse files Browse the repository at this point in the history
@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.
  • Loading branch information
delivrance committed May 1, 2018
1 parent 1dc4306 commit f29b8bb
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions pyrogram/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,8 @@ def stop(self):
for i in self.media_sessions.values():
i.stop()

self.media_sessions.clear()

self.is_started = False
self.session.stop()

Expand Down Expand Up @@ -2992,10 +2994,10 @@ def get_file(self,
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,
Expand All @@ -3011,10 +3013,10 @@ def get_file(self,
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,
Expand Down Expand Up @@ -3082,10 +3084,10 @@ def get_file(self,
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
Expand Down

0 comments on commit f29b8bb

Please sign in to comment.