Skip to content

Commit be655df

Browse files
authored
Merge pull request #875 from minrk/defer-monkeys
avoid jupyter_client.session monkeypatch at import time
2 parents 142583e + 878f297 commit be655df

File tree

9 files changed

+19
-15
lines changed

9 files changed

+19
-15
lines changed

ipyparallel/apps/baseapp.py

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
from traitlets import Bool, Instance, Unicode, default, observe
1818
from traitlets.config.application import LevelFormatter, catch_config_error
1919

20+
from ipyparallel import util
21+
2022
from .._version import __version__
2123

2224
# FIXME: CUnicode is needed for cli parsing
@@ -136,6 +138,7 @@ def _default_session(self):
136138
@catch_config_error
137139
def initialize(self, argv=None):
138140
"""initialize the app"""
141+
util._disable_session_extract_dates()
139142
self.init_config_from_env()
140143
super().initialize(argv)
141144
self.init_deprecated_config()

ipyparallel/client/client.py

+1
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ def __init__(
570570
)
571571
raise ValueError(msg.format(exc.message))
572572

573+
util._disable_session_extract_dates()
573574
self.session = Session(**extra_args)
574575

575576
self._query_socket = self._context.socket(zmq.DEALER)

ipyparallel/controller/heartmonitor.py

+2
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from zmq.devices import ThreadDevice, ThreadMonitoredQueue
1919
from zmq.eventloop.zmqstream import ZMQStream
2020

21+
from ipyparallel import util
2122
from ipyparallel.util import bind, connect, log_errors, set_hwm
2223

2324

@@ -120,6 +121,7 @@ class HeartMonitor(LoggingConfigurable):
120121

121122
@default("session")
122123
def _default_session(self):
124+
util._disable_session_extract_dates()
123125
return Session(parent=self)
124126

125127
loop = Instance(ioloop.IOLoop)

ipyparallel/controller/scheduler.py

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def _default_loop(self):
4646

4747
@default("session")
4848
def _default_session(self):
49+
util._disable_session_extract_dates()
4950
return jupyter_client.session.Session(parent=self)
5051

5152
client_stream = Instance(

ipyparallel/engine/app.py

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
from traitlets.config import Config
3838
from zmq.eventloop import zmqstream
3939

40+
from ipyparallel import util
4041
from ipyparallel.apps.baseapp import (
4142
BaseParallelApplication,
4243
base_aliases,
@@ -405,6 +406,7 @@ def load_connection_file(self):
405406

406407
config.Session.packer = d['pack']
407408
config.Session.unpacker = d['unpack']
409+
util._disable_session_extract_dates()
408410
self.session = Session(parent=self)
409411

410412
self.log.debug("Config changed:")

ipyparallel/engine/nanny.py

+1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def __init__(
6868
self.curve_secretkey = curve_secretkey
6969
self.config = config
7070
self.pipe = pipe
71+
util._disable_session_extract_dates()
7172
self.session = Session(config=self.config)
7273

7374
self.log = local_logger(f"{self.__class__.__name__}.{engine_id}", log_level)

ipyparallel/tests/test_db.py

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
class TaskDBTest:
2323
def setUp(self):
24+
util._disable_session_extract_dates()
2425
self.session = Session()
2526
self.db = self.create_db()
2627
self.load_records(16)

ipyparallel/util.py

+7-14
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from IPython import get_ipython
2525
from IPython.core.profiledir import ProfileDir, ProfileDirError
2626
from IPython.paths import get_ipython_dir
27+
from jupyter_client import session
2728
from jupyter_client.localinterfaces import is_public_ip, localhost, public_ips
2829
from tornado.ioloop import IOLoop
2930
from traitlets.log import get_logger
@@ -599,21 +600,13 @@ def _v(version_s):
599600
return tuple(int(s) for s in re.findall(r"\d+", version_s))
600601

601602

602-
def _patch_jupyter_client_dates():
603-
"""Monkeypatch jupyter_client.extract_dates to be nondestructive wrt timezone info"""
604-
import jupyter_client
605-
606-
if _v(jupyter_client.__version__) < _v('5.0'):
607-
from jupyter_client import session
608-
609-
if hasattr(session, '_save_extract_dates'):
610-
return
611-
session._save_extract_dates = session.extract_dates
612-
session.extract_dates = extract_dates
613-
603+
@lru_cache()
604+
def _disable_session_extract_dates():
605+
"""Monkeypatch jupyter_client.extract_dates to be a no-op
614606
615-
# FIXME: remove patch when we require jupyter_client 5.0
616-
_patch_jupyter_client_dates()
607+
avoids performance problem parsing unused timestamp strings
608+
"""
609+
session.extract_dates = lambda obj: obj
617610

618611

619612
def progress(*args, widget=None, **kwargs):

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ dependencies = [
4141
"pyzmq>=18",
4242
"traitlets>=4.3",
4343
"ipython>=4",
44-
"jupyter_client",
44+
"jupyter_client>=5",
4545
"ipykernel>=4.4",
4646
"tornado>=5.1",
4747
"psutil",

0 commit comments

Comments
 (0)