Skip to content

Commit

Permalink
Merge pull request #109 from alfredodeza/issue-108
Browse files Browse the repository at this point in the history
re-introduce linecache usage again
  • Loading branch information
nicoddemus authored Aug 30, 2019
2 parents f14ceaa + 507ac94 commit f923a3e
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 9 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
1.7.0 (08-08-2019)
1.7.1 (2019-08-28)
------------------

* `#108 <https://github.com/pytest-dev/execnet/issues/108>`__: Revert ``linecache`` optimization introduced in ``1.7.0`` which
broke remote execution.

1.7.0 (2019-08-08)
------------------

* `#102 <https://github.com/pytest-dev/execnet/pull/102>`__: Show paths in stack traces
Expand Down
7 changes: 3 additions & 4 deletions execnet/gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
(c) 2004-2013, Holger Krekel and others
"""
import inspect
import linecache
import os
import sys
import textwrap
Expand Down Expand Up @@ -111,10 +112,8 @@ def remote_exec(self, source, **kwargs):
file_name = None
if isinstance(source, types.ModuleType):
file_name = inspect.getsourcefile(source)
if not file_name:
source = inspect.getsource(source)
else:
source = None
linecache.updatecache(file_name)
source = inspect.getsource(source)
elif isinstance(source, types.FunctionType):
call_name = source.__name__
file_name = inspect.getsourcefile(source)
Expand Down
4 changes: 0 additions & 4 deletions execnet/gateway_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"""
from __future__ import with_statement

import linecache
import os
import struct
import sys
Expand Down Expand Up @@ -1077,9 +1076,6 @@ def executetask(self, item):
name = name.encode("ascii")
newkwargs[name] = value
kwargs = newkwargs
if source is None:
assert file_name, file_name
source = "".join(linecache.updatecache(file_name))
loc = {"channel": channel, "__name__": "__channelexec__"}
self._trace("execution starts[%s]: %s" % (channel.id, repr(source)[:50]))
channel._executing = True
Expand Down
31 changes: 31 additions & 0 deletions testing/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,37 @@ def test_remote_exec_module(self, tmpdir, gw):
name = channel.receive()
assert name == 2

def test_remote_exec_module_is_removed(self, gw, tmpdir, monkeypatch):
remotetest = tmpdir.join("remote.py")
remotetest.write(
dedent(
"""
def remote():
return True
if __name__ == '__channelexec__':
for item in channel: # noqa
channel.send(eval(item)) # noqa
"""
)
)

monkeypatch.syspath_prepend(tmpdir)
import remote

ch = gw.remote_exec(remote)
# simulate sending the code to a remote location that does not have
# access to the source
tmpdir.remove()
ch.send("remote()")
try:
result = ch.receive()
finally:
ch.close()

assert result is True

def test_remote_exec_module_with_traceback(self, gw, tmpdir, monkeypatch):
remotetest = tmpdir.join("remotetest.py")
remotetest.write(
Expand Down

0 comments on commit f923a3e

Please sign in to comment.