Skip to content

Commit f923a3e

Browse files
authored
Merge pull request #109 from alfredodeza/issue-108
re-introduce linecache usage again
2 parents f14ceaa + 507ac94 commit f923a3e

File tree

4 files changed

+41
-9
lines changed

4 files changed

+41
-9
lines changed

CHANGELOG.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
1.7.0 (08-08-2019)
1+
1.7.1 (2019-08-28)
2+
------------------
3+
4+
* `#108 <https://github.com/pytest-dev/execnet/issues/108>`__: Revert ``linecache`` optimization introduced in ``1.7.0`` which
5+
broke remote execution.
6+
7+
1.7.0 (2019-08-08)
28
------------------
39

410
* `#102 <https://github.com/pytest-dev/execnet/pull/102>`__: Show paths in stack traces

execnet/gateway.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
(c) 2004-2013, Holger Krekel and others
55
"""
66
import inspect
7+
import linecache
78
import os
89
import sys
910
import textwrap
@@ -111,10 +112,8 @@ def remote_exec(self, source, **kwargs):
111112
file_name = None
112113
if isinstance(source, types.ModuleType):
113114
file_name = inspect.getsourcefile(source)
114-
if not file_name:
115-
source = inspect.getsource(source)
116-
else:
117-
source = None
115+
linecache.updatecache(file_name)
116+
source = inspect.getsource(source)
118117
elif isinstance(source, types.FunctionType):
119118
call_name = source.__name__
120119
file_name = inspect.getsourcefile(source)

execnet/gateway_base.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
"""
1515
from __future__ import with_statement
1616

17-
import linecache
1817
import os
1918
import struct
2019
import sys
@@ -1077,9 +1076,6 @@ def executetask(self, item):
10771076
name = name.encode("ascii")
10781077
newkwargs[name] = value
10791078
kwargs = newkwargs
1080-
if source is None:
1081-
assert file_name, file_name
1082-
source = "".join(linecache.updatecache(file_name))
10831079
loc = {"channel": channel, "__name__": "__channelexec__"}
10841080
self._trace("execution starts[%s]: %s" % (channel.id, repr(source)[:50]))
10851081
channel._executing = True

testing/test_gateway.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,37 @@ def test_remote_exec_module(self, tmpdir, gw):
122122
name = channel.receive()
123123
assert name == 2
124124

125+
def test_remote_exec_module_is_removed(self, gw, tmpdir, monkeypatch):
126+
remotetest = tmpdir.join("remote.py")
127+
remotetest.write(
128+
dedent(
129+
"""
130+
def remote():
131+
return True
132+
133+
if __name__ == '__channelexec__':
134+
for item in channel: # noqa
135+
channel.send(eval(item)) # noqa
136+
137+
"""
138+
)
139+
)
140+
141+
monkeypatch.syspath_prepend(tmpdir)
142+
import remote
143+
144+
ch = gw.remote_exec(remote)
145+
# simulate sending the code to a remote location that does not have
146+
# access to the source
147+
tmpdir.remove()
148+
ch.send("remote()")
149+
try:
150+
result = ch.receive()
151+
finally:
152+
ch.close()
153+
154+
assert result is True
155+
125156
def test_remote_exec_module_with_traceback(self, gw, tmpdir, monkeypatch):
126157
remotetest = tmpdir.join("remotetest.py")
127158
remotetest.write(

0 commit comments

Comments
 (0)