{"id":20597167,"url":"https://github.com/pandolia/remote_embed","last_synced_at":"2025-04-15T00:07:32.698Z","repository":{"id":57461081,"uuid":"162289931","full_name":"pandolia/remote_embed","owner":"pandolia","description":"A remote version of python code.interact.","archived":false,"fork":false,"pushed_at":"2018-12-28T16:15:53.000Z","size":40,"stargazers_count":3,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T00:06:50.326Z","etag":null,"topics":["interact","python-debug","python-debugger","remote-debugger"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pandolia.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-12-18T13:08:32.000Z","updated_at":"2024-05-08T13:37:52.000Z","dependencies_parsed_at":"2022-09-17T04:00:28.683Z","dependency_job_id":null,"html_url":"https://github.com/pandolia/remote_embed","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pandolia%2Fremote_embed","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pandolia%2Fremote_embed/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pandolia%2Fremote_embed/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pandolia%2Fremote_embed/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pandolia","download_url":"https://codeload.github.com/pandolia/remote_embed/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248981267,"owners_count":21193147,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["interact","python-debug","python-debugger","remote-debugger"],"created_at":"2024-11-16T08:20:53.948Z","updated_at":"2025-04-15T00:07:32.678Z","avatar_url":"https://github.com/pandolia.png","language":"Python","readme":"\nIntroduction\n-------------\n\n**remote_embed** is a remote version of [python code.interact](https://docs.python.org/2/library/code.html#code.interact) which let your remote python process break into interactive mode so that you can attach to and interact with it from a local machine(or another terminal in the same machine).\n\nThe only function you will use is **embed()**. As I said, it is just a remote version of **code.interact()**.\n\nWhen you need remote_embed\n---------------------------\n\n* When you want to debug a python process runs at a remote mathine.\n* When you want to debug a GUI python process which without a terminal.\n* When you want to debug a C/C++ process which embeds python intepreter in itself.\n\nUsage\n-----\n\n1. Install **remote_embed** in your remote machine:\n\n```bash\npip install remote_embed\n```\n\nOr just put [remote_embed.py](https://raw.githubusercontent.com/pandolia/remote_embed/master/remote_embed.py) into your remote project directory.\n\n2. In remote script, import **remote_embed** and insert **embed** at the line where you want to break:\n\n```python\nfrom remote_embed import Embed; embed = Embed('your_ip', your_port)\n\na = 0\n\ndef myfunc(x, y, z):\n    print(a, x, y, z)\n    embed()\n    print(a, x, y, z)\n\nmyfunc(1, 2, [3])\n```\n\nRun the script on the remote machine, you will see the remote process break at that line and waiting for a local debugger to attach.\n\n3. Run **nc {yourip} {port}** on your local machine to attach to and interact with the remote process. You can read local variables and global variables of the remote process, and input python statements/expressions to be executed/evaluated in the remote process. When you finish, type **exit** or just close the local terminal. This will cause the remote process jump out from interactive mode and resume the execution.\n\nIn windows, you can download **nc** from [here](https://eternallybored.org/misc/netcat/).\n\nIf you just want to interact with another process at the same machine, just use **embed = Embed(port=7000)**. This will make the process break and listen on **127.0.0.1:7000**. Then you can open another terminal and run **nc 127.0.0.1 7000** to attach to and interact with it.\n\nIf you just use **embed = Embed()**, the process will listen on **127.0.0.1:first_available_port**, and print the port being listened on its terminal(specifically: its sys.stderr).\n\n4. If you are tired of opening another terminal and typing nc commands, you can pass a **popup** parameter and make the process break and then automatically popup a new terminal which has already attached to itself. On windows, you just need to provide the path of **nc.exe**, for example:\n\n```python\nfrom remote_embed import Embed; embed = Embed(popup='\\\\yourpath\\\\nc.exe')\n\ndef myfunc(x, y, z):\n    # ...\n    embed() # break here and popup a new interactive terminal\n    # ...\n```\n\nOn other platforms, you need to write a popup function, take MacOS for example:\n\n```python\nimport subprocess\n\n# this function must popup a new terminal which runs \"nc {host} {port}\"\n# and return immediately. DO NOT BLOCK.\ndef mypopup(host, port):\n    subprocess.call(['open','-W','-a','Terminal.app', 'nc', host, str(port)])\n\nfrom remote_embed import Embed; embed = Embed(popup=mypopup)\n\ndef myfunc(x, y, x):\n    # ...\n    embed() # break here and popup a new interactive terminal\n    # ...\n```\n\n\nDetail of the Embed function\n-----------------------------\n\n```python\ndef Embed(\n    host='127.0.0.1',           # the ip which you want to listen at\n    port=0,                     # the port which you want to listen at\n    popup=None,                 # a popup function or the path of 'nc.exe'(in windows)\n    log_writer=sys.stderr,      # the logger's writer\n    this_coding=None,           # the coding of the process which you want to debug,\n                                # default to 'gb18030' in windows, and 'utf8' in other platforms\n    debugger_coding=None,       # the coding of the debugger, default to `this_coding`\n    help_info=None              # a help infomation printed at the debugger's terminal when it attached,\n                                # default to the line infomation of the break point\n):\n\n    # ...\n\n    def embed():\n        # ...\n    \n    return embed\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpandolia%2Fremote_embed","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpandolia%2Fremote_embed","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpandolia%2Fremote_embed/lists"}