Coder Social home page Coder Social logo

Comments (9)

Ian2020 avatar Ian2020 commented on July 18, 2024

Hi, great project. Is there any workaround for this issue?

from chopsticks.

lordmauve avatar lordmauve commented on July 18, 2024

There are several. The cleanest one is is to make sure that the functions you want to call remotely are in a separate module to your __main__ module. This is good organisational practice anyway.

from chopsticks.

Ian2020 avatar Ian2020 commented on July 18, 2024

Sorry, I should have thought of that before I posted! Thanks very much.

from chopsticks.

lordmauve avatar lordmauve commented on July 18, 2024

If you want a single-file solution, there is one, but it's subtle and cludgey:

Say your script is called my_script.py:

def my_remote_func():
    ...

if __name__ == '__main__':
    from my_script import my_remote_func
    # now my_remote_func is my_script.my_remote_func, which can be unpickled
    from chopsticks.tunnel import Tunnel
    Tunnel(hostname).call(my_remote_func)

from chopsticks.

Ian2020 avatar Ian2020 commented on July 18, 2024

Very kind of you to provide that snippet - I will use it. Just trying out Chopsticks quickly for first time today and was too lazy to use modules! It's already saved me some time.

from chopsticks.

romanlevin avatar romanlevin commented on July 18, 2024

The same (or a very similar) issue exists in Python 3, with a much less friendly error:

chopsticks.tunnel.RemoteException: Host 'local' raised exception; traceback follows

    Traceback (most recent call last):
      File "bubble.py", line 139, in wrapper
      File "bubble.py", line 152, in handle_call_thread
      File "<frozen importlib._bootstrap>", line 969, in _find_and_load
      File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
      File "bubble.py", line 119, in load_module
      File "controller://run.py", line 3, in <module>
      File "<frozen importlib._bootstrap>", line 969, in _find_and_load
      File "<frozen importlib._bootstrap>", line 958, in _find_and_load_unlocked
      File "<frozen importlib._bootstrap>", line 664, in _load_unlocked
      File "<frozen importlib._bootstrap>", line 634, in _load_backward_compatible
      File "bubble.py", line 119, in load_module
      File "controller://chopsticks/tunnel.py", line 358, in <module>
        class SubprocessTunnel(PipeTunnel):
      File "controller://chopsticks/tunnel.py", line 366, in SubprocessTunnel
        '__bubble = sys.stdin.read(%d); ' % len(bubble) +
    TypeError: object of type 'NoneType' has no len()

from chopsticks.

lordmauve avatar lordmauve commented on July 18, 2024

@romanlevin - that's actually caused by issue #6.

Specifically, issue #6 means you can't import chopsticks on the remote host at the moment. If you move your chopsticks imports to the if __name__ == __main__ block, then it should work.

from chopsticks.

romanlevin avatar romanlevin commented on July 18, 2024

@lordmauve oh I see, thanks!

from chopsticks.

lordmauve avatar lordmauve commented on July 18, 2024

The solution to issue #17 will fix this issue also.

from chopsticks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.