Skip to content

Commit

Permalink
fixed possible logging thread zombies which prevent proper Kodi exit.
Browse files Browse the repository at this point in the history
  • Loading branch information
afedchin committed Dec 12, 2016
1 parent ed4dd26 commit 70b4c90
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 5 deletions.
4 changes: 2 additions & 2 deletions resources/site-packages/xbmctorrent/logpipe.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import threading
import re

import xbmc

class LogPipe(threading.Thread):

Expand All @@ -22,7 +22,7 @@ def run(self):
for line in iter(f.readline, ""):
line = re.sub(r'^\d+/\d+/\d+ \d+:\d+:\d+ ', '', line)
self.logger(line.strip())
if self.stop.is_set():
if xbmc.abortRequested or self.stop.is_set():
break
self.logger("Logging thread finished.")

Expand Down
20 changes: 17 additions & 3 deletions resources/site-packages/xbmctorrent/torrent2http.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import sys
import stat
import subprocess
import time
import xbmcaddon
from xbmctorrent.common import RESOURCES_PATH
from xbmctorrent.osarch import PLATFORM
Expand Down Expand Up @@ -86,10 +87,11 @@ def start(**kwargs):

plugin.log.debug(repr(args))

log_thread = logpipe.LogPipe(logger)
kwargs = {
"cwd": torrent2http_dir,
"stderr": logpipe.LogPipe(logger),
"stdout": logpipe.LogPipe(logger)
"stderr": log_thread,
"stdout": log_thread
}
if PLATFORM["os"] == "windows":
si = subprocess.STARTUPINFO()
Expand All @@ -105,10 +107,22 @@ def start(**kwargs):
proc = subprocess.Popen(args, **kwargs)
proc.bind_address = bind_address
def proc_close():
if not proc.poll():
if proc.poll() is None:
try:
url_get("http://%s/shutdown" % proc.bind_address, with_immunicity=False)
except:
pass
finished = False
os.close(log_thread.write_fd)
start = time.time()
while (time.time() - start) < 10:
time.sleep(0.2)
if proc.poll() is not None:
finished = True
break
if not finished:
logger("timeout occured while shutting down")
proc.kill()
proc.wait()
proc.close = proc_close
return proc

0 comments on commit 70b4c90

Please sign in to comment.