Skip to content

Weave "AttributeError" on AWS Lambda #9

Open
@matdodgson

Description

@matdodgson

Hi!
Great library - thanks for your work!
I'm hosting some Python 3.6 code on AWS Lambda and I have a strangely intermittent error (occurs about 80% of the time) with aspectlib weave on the Python Requests library. Here's the exception:

File "/var/task/aspectlib/__init__.py", line 413, in weave
weave(item, aspects, **options) for item in target
File "/var/task/aspectlib/__init__.py", line 413, in <listcomp>
weave(item, aspects, **options) for item in target
File "/var/task/aspectlib/__init__.py", line 505, in weave
return weave_instance(target, aspects, **options)
File "/var/task/aspectlib/__init__.py", line 554, in weave_instance
patch_module(instance, attr, _checked_apply(fixed_aspect, realfunc, module=None), **options)
File "/var/task/aspectlib/__init__.py", line 722, in patch_module
setattr(module, alias, replacement)
AttributeError: '__logged__' object attribute 'advising_function' is read-only

Here's my weave call:

weave([Session.send],
      debug.log(stacktrace=False),
      lazy=True)

Never have a problem on my Ubuntu 18 dev machine. Don't have a problem on a normal hosting environment - such as an EC2 instance. This problem only seems to occur on AWS Lambda.

I have made a patch to catch the exception and debug log the error. Please see the pull request. The catch is not very specific; I wanted to avoid recording the rollback of the weave and the "seen = True" part.

Activity

ionelmc

ionelmc commented on Jun 6, 2018

@ionelmc
Owner

I suspect the actual problem is that that weave([Session.send], debug.log(stacktrace=False), lazy=True) is run multiple times in the same process and 20% of the time aws lambda spawns new process when running your code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Weave "AttributeError" on AWS Lambda · Issue #9 · ionelmc/python-aspectlib