Skip to content

Commit 5a355d2

Browse files
committed
Don't use Python's time.sleep().
1 parent 46703b2 commit 5a355d2

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

service.py

+13-3
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
import shutil
1515
import sys
1616
import tempfile
17-
import time
1817
from unicodedata import normalize
1918
from urllib import FancyURLopener, unquote, quote_plus, urlencode, quote
2019
from urlparse import parse_qs
@@ -63,6 +62,8 @@
6362

6463
PAGE_ENCODING = 'latin1'
6564

65+
kodi_major_version = None
66+
6667

6768
# ============================
6869
# Regular expression patterns
@@ -330,7 +331,6 @@ def _handle_compressed_subs(workdir, compressed_file, ext):
330331
"""
331332
Uncompress 'compressed_file' in 'workdir'.
332333
"""
333-
kodi_major_version = int(xbmc.getInfoLabel('System.BuildVersion').split('.')[0])
334334
if ext == 'rar' and kodi_major_version >= 18:
335335
src = 'archive' + '://' + quote_plus(compressed_file) + '/'
336336
(cdirs, cfiles) = xbmcvfs.listdir(src)
@@ -509,12 +509,22 @@ def _cleanup_tempdirs(profile_path):
509509
log(u"Results: %d of %d dirs removed" % (ok, total + 1), level=LOGDEBUG)
510510

511511

512+
def sleep(secs):
513+
"""Sleeps efficiently for secs seconds"""
514+
if kodi_major_version > 13:
515+
xbmc.Monitor().waitForAbort(secs)
516+
else:
517+
xbmc.sleep(1000 * secs)
518+
519+
512520
def main():
513521
"""Main entry point of the script when it is invoked by XBMC."""
522+
global kodi_major_version
514523
# Get parameters from XBMC and launch actions
515524
params = get_params(sys.argv)
516525
action = params.get('action', 'Unknown')
517526
xbmc.log(u"SUBDIVX - Version: %s -- Action: %s" % (__version__, action), level=LOGNOTICE)
527+
kodi_major_version = int(xbmc.getInfoLabel('System.BuildVersion').split('.')[0])
518528

519529
if action in ('search', 'manualsearch'):
520530
item = {
@@ -591,7 +601,7 @@ def main():
591601
# Send end of directory to XBMC
592602
xbmcplugin.endOfDirectory(int(sys.argv[1]))
593603

594-
time.sleep(2)
604+
sleep(2)
595605
if __addon__.getSetting('show_nick_in_place_of_lang') == 'true':
596606
_double_dot_fix_hack(params['filename'].encode('utf-8'))
597607
_cleanup_tempdir(workdir, verbose=True)

0 commit comments

Comments
 (0)