如何彻底卸载python中的readline模块?

发布于 2025-01-20 10:21:55 字数 820 浏览 4 评论 0原文

我想通过完全摆脱它来动态禁用阅读线功能。不是通过禁用选项卡完成或任何其他提供的功能,而是通过完全解开免费资源。

我有一个程序,该程序将NCURS用于显示目的,但是返回到普通终端,您可以在其中将内容键入Python的Input()函数字段。除了终端调整和更新诅咒内部的终端大小和COLS变量外,一切都起作用。调整大小时会出现此可怕的错误:

    c = stdscr.get_wch()
_curses.error: no input

最小的程序要复制:

import readline
import curses

def c_main(stdscr):
    while True:
        c = stdscr.get_wch()
        stdscr.insstr(0, 0, repr(c))

curses.wrapper(c_main)

我尝试从sys.modules中删除模块,摆脱了名称del readline,垃圾收集,收集,收集,但这都是徒劳的。

print(readline.__file__)

给予:/usr/lib/python3.10/lib-dynload/readline.cpython-310-x86_64-linux-gnu.so

我想我知道我必须获得此文件的句柄不知何故,用CTYPE卸载它,但我不知道该怎么做。另外,有人可以指向我如何调和这两个库以使调整大小的工作的正确方向?谢谢。

I want to dynamically disable the readline functionality by completely getting rid of it. Not by disabling tab completion or any other provided functionality, but to completely unhook it, free resources.

I have a program that uses ncurses for display purposes, but returns to the normal terminal where you can type stuff into Python's input() function field. Everything works except for terminal resizing and updating the LINES and COLS variables inside curses. We are presented with this dreaded error upon resizing:

    c = stdscr.get_wch()
_curses.error: no input

Minimal program to reproduce:

import readline
import curses

def c_main(stdscr):
    while True:
        c = stdscr.get_wch()
        stdscr.insstr(0, 0, repr(c))

curses.wrapper(c_main)

I tried removing the module from sys.modules, getting rid of the name del readline, garbage collecting, but it is all futile.

print(readline.__file__)

gives: /usr/lib/python3.10/lib-dynload/readline.cpython-310-x86_64-linux-gnu.so

I think I understand that I have to obtain the handle for this file and somehow unload it with ctypes, but I have no idea how to do it. Alternatively, could someone point me in the right direction on how to reconcile these two libraries to make resizing work? Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文