Import ctypes only when necessary

Closes #4541
This commit is contained in:
pukkandan 2022-08-03 17:47:38 +05:30
parent b99ba3df09
commit fe0918bb65
No known key found for this signature in database
GPG key ID: 7EEE9E1E817D0A39
2 changed files with 9 additions and 7 deletions

View file

@ -6,7 +6,6 @@ import calendar
import codecs
import collections
import contextlib
import ctypes
import datetime
import email.header
import email.utils
@ -1983,6 +1982,7 @@ class LockingUnsupportedError(OSError):
# Cross-platform file locking
if sys.platform == 'win32':
import ctypes
import ctypes.wintypes
import msvcrt
@ -2362,9 +2362,10 @@ def fix_xml_ampersands(xml_str):
def setproctitle(title):
assert isinstance(title, str)
# ctypes in Jython is not complete
# http://bugs.jython.org/issue2148
if sys.platform.startswith('java'):
# Workaround for https://github.com/yt-dlp/yt-dlp/issues/4541
try:
import ctypes
except ImportError:
return
try: