Patchwork [4,of,6] socketserver: force demandimport to load python3-only modules

login
register
mail settings
Submitter Jun Wu
Date May 9, 2016, 12:06 a.m.
Message ID <7a84412fa25901e35b2d.1462752383@x1c>
Download mbox | patch
Permalink /patch/14980/
State Changes Requested
Headers show

Comments

Jun Wu - May 9, 2016, 12:06 a.m.
# HG changeset patch
# User Jun Wu <quark@fb.com>
# Date 1462531194 -3600
#      Fri May 06 11:39:54 2016 +0100
# Node ID 7a84412fa25901e35b2d791b704aa3d2e3dd434f
# Parent  0e68b512f4d9dad9c064342b0deebd45238f0cdf
socketserver: force demandimport to load python3-only modules

The current socketserver has some "except ImportError" code to detect Python 3
only features and fallback to Python 2 gracefully. With demandimport enabled,
the ImportError will be deferred and the fallback code will not run.

This patch addresses the issue by accessing a member of those modules, forcing
demandimport to load them.

Patch

diff --git a/mercurial/socketserver.py b/mercurial/socketserver.py
--- a/mercurial/socketserver.py
+++ b/mercurial/socketserver.py
@@ -136,6 +136,7 @@ 
 import socket
 try:
     import threading
+    threading.Thread # force demandimport to load the module
 except ImportError:
     import dummy_threading as threading
 
@@ -164,6 +165,7 @@ 
 
 try:
     import selectors
+    selectors.EVENT_READ # force demandimport to load the module
 except ImportError:
     # Python 2 does not have selectors. This is a minimal "selectors"
     # module just satisfying the needs of the "socketserver" module.