mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py3: Another place to port listener addresses
This commit is contained in:
parent
237c64b9da
commit
eaac4d254d
@ -19,7 +19,7 @@ from multiprocessing.connection import Listener, arbitrary_address
|
|||||||
from threading import RLock, Thread
|
from threading import RLock, Thread
|
||||||
|
|
||||||
from calibre import detect_ncpus as cpu_count
|
from calibre import detect_ncpus as cpu_count
|
||||||
from calibre.constants import DEBUG, islinux, iswindows
|
from calibre.constants import DEBUG, islinux, iswindows, ispy3
|
||||||
from calibre.ptempfile import base_dir
|
from calibre.ptempfile import base_dir
|
||||||
from calibre.utils.ipc import eintr_retry_call
|
from calibre.utils.ipc import eintr_retry_call
|
||||||
from calibre.utils.ipc.launch import Worker
|
from calibre.utils.ipc.launch import Worker
|
||||||
@ -136,7 +136,9 @@ if islinux:
|
|||||||
# Use abstract named sockets on linux to avoid creating unnecessary temp files
|
# Use abstract named sockets on linux to avoid creating unnecessary temp files
|
||||||
prefix = u'\0calibre-ipc-listener-%d-%%d' % os.getpid()
|
prefix = u'\0calibre-ipc-listener-%d-%%d' % os.getpid()
|
||||||
while True:
|
while True:
|
||||||
address = (prefix % next(_name_counter)).encode('ascii')
|
address = (prefix % next(_name_counter))
|
||||||
|
if not ispy3 and not isinstance(address, bytes):
|
||||||
|
address = address.encode('ascii')
|
||||||
try:
|
try:
|
||||||
l = LinuxListener(address=address, authkey=authkey, backlog=backlog)
|
l = LinuxListener(address=address, authkey=authkey, backlog=backlog)
|
||||||
return address, l
|
return address, l
|
||||||
@ -159,7 +161,7 @@ else:
|
|||||||
while max_tries > 0:
|
while max_tries > 0:
|
||||||
max_tries -= 1
|
max_tries -= 1
|
||||||
address = prefix % next(_name_counter)
|
address = prefix % next(_name_counter)
|
||||||
if not isinstance(address, bytes):
|
if not ispy3 and not isinstance(address, bytes):
|
||||||
address = address.encode('utf-8') # multiprocessing needs bytes in python 2
|
address = address.encode('utf-8') # multiprocessing needs bytes in python 2
|
||||||
try:
|
try:
|
||||||
return address, Listener(address=address, authkey=authkey, backlog=backlog)
|
return address, Listener(address=address, authkey=authkey, backlog=backlog)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user