我在Python 2.7.8下使用机器人框架3.0。机器人框架的文档(http://robotframework.org/robotframework/latest/RobotFrameworkUserGuide.html#programmatic-logging-apis)指出
除了新的公共日志记录 API 之外,Robot Framework 还提供对 Python 标准日志记录模块的内置支持。这样一来,模块的根记录器接收到的所有消息都会自动传播到 Robot Framework 的日志文件中。
我制作了一个简短的库文件来测试这一点:
from logging import debug, error, info, warn
def try_logging():
info("This is merely a humble info message.")
debug("Most users never saw me.")
warn("I warn you about something.")
error("Something bad happened.")
Run Code Online (Sandbox Code Playgroud)
我的测试用例是:
*** Test Cases ***
Logtest
Try logging
Run Code Online (Sandbox Code Playgroud)
当我运行它时,它是一个“通过”的情况,但没有任何内容记录到 HTML 日志中。测试执行日志具有应有的西装、案例和关键字,但是当我展开它们时,除了“开始/结束/已过去”行之外,没有记录任何内容。
如何将 Python 记录器消息转发给 Robot?正如您所看到的,所谓的自动传播并不会自动运行。我的目标是编写一个可以在有或没有 Robot Fw 的情况下运行的库。
提前寻求您的帮助。
在我的 Python 3.3 代码中,我使用了 ttk 库中的一些组合框,它们运行良好,但如果我使用其中任何一个,当我使用 X 按钮关闭窗口时,就会出现异常。这是一个例子:
from tkinter import Tk,Label,Button
from tkinter import ttk
from tkinter.ttk import Combobox
def cbox_do(event):
'Used for cbox.'
clabel.config(text=cbox.get())
a = Tk()
cbox = Combobox(a, value=('Luke','Biggs','Wedge'), takefocus=0)
cbox.bind("<<ComboboxSelected>>", cbox_do)
cbox.pack()
clabel = Label(a)
clabel.pack()
a.mainloop()
Run Code Online (Sandbox Code Playgroud)
如果在没有选择值的情况下关闭它,一切都很好,但尝试在选择值后关闭它,它会退出,但会在 python 命令行中打印以下错误:
can't invoke "winfo" command: application has been destroyed
while executing
"winfo exists $w"
(procedure "ttk::entry::AutoScroll" line 3)
invoked from within
"ttk::entry::AutoScroll .41024560"
(in namespace inscope "::" script line 1)
invoked from within
"::namespace inscope :: …Run Code Online (Sandbox Code Playgroud) 我目前正在用Python编写一个简单的棋盘游戏,我刚刚意识到垃圾收集不会在重新加载图像时从内存中清除丢弃的位图数据.它只在游戏启动或加载或分辨率发生变化时发生,但它会使所消耗的内存倍增,所以我不能让这个问题得不到解决.
当重新加载图像时,所有参考都被转移到新的图像数据,因为它被绑定到与原始图像数据绑定到的相同的变量.我试图通过使用强制垃圾收集,collect()但它没有帮助.
我写了一个小样本来证明我的问题.
from tkinter import Button, DISABLED, Frame, Label, NORMAL, Tk
from PIL.Image import open
from PIL.ImageTk import PhotoImage
class App(Tk):
def __init__(self):
Tk.__init__(self)
self.text = Label(self, text = "Please check the memory usage. Then push button #1.")
self.text.pack()
self.btn = Button(text = "#1", command = lambda : self.buttonPushed(1))
self.btn.pack()
def buttonPushed(self, n):
"Cycle to open the Tab module n times."
self.btn.configure(state = DISABLED) # disable to prevent paralell cycles
if n == 100:
self.text.configure(text = "Overwriting …Run Code Online (Sandbox Code Playgroud) python ×3
tkinter ×2
combobox ×1
logging ×1
memory-leaks ×1
pillow ×1
python-2.7 ×1
python-3.x ×1
ttk ×1