mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Use pipe2 if available
This commit is contained in:
parent
86eb977bb9
commit
a2b16ded41
@ -1,27 +1,40 @@
|
|||||||
__license__ = 'GPL v3'
|
__license__ = 'GPL v3'
|
||||||
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
__copyright__ = '2008, Kovid Goyal <kovid at kovidgoyal.net>'
|
||||||
""" The GUI """
|
""" The GUI """
|
||||||
import os, sys, Queue, threading, glob, signal
|
import glob
|
||||||
|
import os
|
||||||
|
import Queue
|
||||||
|
import signal
|
||||||
|
import sys
|
||||||
|
import threading
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from threading import RLock, Lock
|
from threading import Lock, RLock
|
||||||
from PyQt5.QtWidgets import QStyle # Gives a nicer error message than import from Qt
|
|
||||||
from PyQt5.Qt import (
|
|
||||||
QFileInfo, QObject, QBuffer, Qt, QByteArray, QTranslator, QSocketNotifier,
|
|
||||||
QCoreApplication, QThread, QEvent, QTimer, pyqtSignal, QDateTime, QFontMetrics,
|
|
||||||
QDesktopServices, QFileDialog, QFileIconProvider, QSettings, QIcon, QStringListModel,
|
|
||||||
QApplication, QDialog, QUrl, QFont, QFontDatabase, QLocale, QFontInfo, QT_VERSION)
|
|
||||||
|
|
||||||
from calibre import prints, as_unicode
|
from PyQt5.Qt import (
|
||||||
from calibre.constants import (islinux, iswindows, isbsd, isfrozen, isosx, is_running_from_develop,
|
QT_VERSION, QApplication, QBuffer, QByteArray, QCoreApplication, QDateTime,
|
||||||
plugins, config_dir, filesystem_encoding, isxp, DEBUG, __version__, __appname__ as APP_UID)
|
QDesktopServices, QDialog, QEvent, QFileDialog, QFileIconProvider, QFileInfo,
|
||||||
from calibre.ptempfile import base_dir
|
QFont, QFontDatabase, QFontInfo, QFontMetrics, QIcon, QLocale, QObject,
|
||||||
from calibre.gui2.linux_file_dialogs import check_for_linux_native_dialogs, linux_native_dialog
|
QSettings, QSocketNotifier, QStringListModel, Qt, QThread, QTimer, QTranslator,
|
||||||
from calibre.gui2.qt_file_dialogs import FileDialog
|
QUrl, pyqtSignal
|
||||||
from calibre.utils.config import Config, ConfigProxy, dynamic, JSONConfig
|
)
|
||||||
|
from PyQt5.QtWidgets import QStyle # Gives a nicer error message than import from Qt
|
||||||
|
|
||||||
|
from calibre import as_unicode, prints
|
||||||
|
from calibre.constants import (
|
||||||
|
DEBUG, __appname__ as APP_UID, __version__, config_dir, filesystem_encoding,
|
||||||
|
is_running_from_develop, isbsd, isfrozen, islinux, isosx, iswindows, isxp,
|
||||||
|
plugins
|
||||||
|
)
|
||||||
from calibre.ebooks.metadata import MetaInformation
|
from calibre.ebooks.metadata import MetaInformation
|
||||||
|
from calibre.gui2.linux_file_dialogs import (
|
||||||
|
check_for_linux_native_dialogs, linux_native_dialog
|
||||||
|
)
|
||||||
|
from calibre.gui2.qt_file_dialogs import FileDialog
|
||||||
|
from calibre.ptempfile import base_dir
|
||||||
|
from calibre.utils.config import Config, ConfigProxy, JSONConfig, dynamic
|
||||||
from calibre.utils.date import UNDEFINED_DATE
|
from calibre.utils.date import UNDEFINED_DATE
|
||||||
from calibre.utils.localization import get_lang
|
|
||||||
from calibre.utils.file_type_icons import EXT_MAP
|
from calibre.utils.file_type_icons import EXT_MAP
|
||||||
|
from calibre.utils.localization import get_lang
|
||||||
|
|
||||||
try:
|
try:
|
||||||
NO_URL_FORMATTING = QUrl.None_
|
NO_URL_FORMATTING = QUrl.None_
|
||||||
@ -1036,11 +1049,15 @@ class Application(QApplication):
|
|||||||
|
|
||||||
def setup_unix_signals(self):
|
def setup_unix_signals(self):
|
||||||
import fcntl
|
import fcntl
|
||||||
read_fd, write_fd = os.pipe()
|
if hasattr(os, 'pipe2'):
|
||||||
cloexec_flag = getattr(fcntl, 'FD_CLOEXEC', 1)
|
read_fd, write_fd = os.pipe2(os.O_CLOEXEC | os.O_NONBLOCK)
|
||||||
for fd in (read_fd, write_fd):
|
else:
|
||||||
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
|
read_fd, write_fd = os.pipe()
|
||||||
fcntl.fcntl(fd, fcntl.F_SETFD, flags | cloexec_flag | os.O_NONBLOCK)
|
cloexec_flag = getattr(fcntl, 'FD_CLOEXEC', 1)
|
||||||
|
for fd in (read_fd, write_fd):
|
||||||
|
flags = fcntl.fcntl(fd, fcntl.F_GETFD)
|
||||||
|
fcntl.fcntl(fd, fcntl.F_SETFD, flags | cloexec_flag | os.O_NONBLOCK)
|
||||||
|
|
||||||
for sig in (signal.SIGINT, signal.SIGTERM):
|
for sig in (signal.SIGINT, signal.SIGTERM):
|
||||||
signal.signal(sig, lambda x, y: None)
|
signal.signal(sig, lambda x, y: None)
|
||||||
signal.siginterrupt(sig, False)
|
signal.siginterrupt(sig, False)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user