单击操作按钮后,我有一个程序运行一个很长的过程.当进程正在运行时,根窗口会说它没有响应,即使我知道程序在后台运行.这个程序将发布给我工作的一些人,我想确保他们看到这个时不会惊慌失措并关闭窗口.我的解决方案是将root.update放在正在运行的进程的循环中,但我不确定这是最好的修复.
使用python 3.3
下面是代码示例,以便您了解我正在做什么,这是从主循环中调用的:
def combine(boxes_to, boxes_from, frame):
to_value,to_pos = gui.checkBoxes(boxes_to)
from_value,from_pos = gui.checkBoxes(boxes_from)
frame.destroy()
running = Label(root,text="Running please do not close..",font = (16))
running.pack()
root.update()
map_to = open("map_to",'r')
for line in map_to:
root.update()
process(line)
running.destroy()
map_to.close()
finish = Button(root, text="Done",command=gui.stop)
finish.pack()
Run Code Online (Sandbox Code Playgroud) 例如,在我的 python 代码中,我将字典传递给记录器。
extra_info = {"test":"data"}
logger.info("",extra=extra_info)
Run Code Online (Sandbox Code Playgroud)
我希望得到额外的信息来打印,我认为它在消息中,但是当我使用这种格式时
format=%(asctime)s %(levelname)s %(name)s: %(message)s
Run Code Online (Sandbox Code Playgroud)
未打印 extra_info 内容。我只是得到以下
2016/06/17 13:10:47 INFO test:
Run Code Online (Sandbox Code Playgroud) 我有一个混合内容的XML文档,我在Dataframe中使用自定义架构来解析它.我遇到的问题是架构只会选择"测量"的文本.
XML看起来像这样
<QData>
<Measure> some text here
<Answer>Answer1</Answer>
<Question>Question1</Question>
</Measure>
<Measure> some text here
<Answer>Answer1</Answer>
<Question>Question1</Question>
</Meaure>
</QData>
Run Code Online (Sandbox Code Playgroud)
我的架构如下:
def getCustomSchema():StructType = {StructField("QData",
StructType(Array(
StructField("Measure",
StructType( Array(
StructField("Answer",StringType,true),
StructField("Question",StringType,true)
)),true)
)),true)}
Run Code Online (Sandbox Code Playgroud)
当我尝试访问Measure中的数据时,我只得到"这里的一些文本",当我尝试从Answer获取信息时它失败了.我也只是得到一个测量.
编辑:这是我试图访问数据的方式
val result = sc.read.format("com.databricks.spark.xml").option("attributePrefix", "attr_").schema(getCustomSchema)
.load(filename.toString)
val qDfTemp = result.mapPartitions(partition =>{val mapper = new QDMapper();partition.map(row=>{mapper(row)}).flatMap(list=>list)}).toDF()
case class QDMapper(){
def apply(row: Row):List[QData]={
val qDList = new ListBuffer[QData]()
val qualData = row.getAs[Row]("QData") //When I print as list I get the first Measure text and that is it
val measure …Run Code Online (Sandbox Code Playgroud) 我知道multiprocessing使用酸洗以使进程在不同的CPU上运行,但我认为我对于被腌制的东西有点困惑.让我们看看这段代码.
from multiprocessing import Process
def f(I):
print('hello world!',I)
if __name__ == '__main__':
for I in (range1, 3):
Process(target=f,args=(I,)).start()
Run Code Online (Sandbox Code Playgroud)
我假设被腌制的是进入def f(I)的论点.首先,这个假设是正确的吗?
其次,让我们说它里面f(I)有一个函数调用:
def f(I):
print('hello world!',I)
randomfunction()
Run Code Online (Sandbox Code Playgroud)
这个randomfunction定义是否也被腌制,或者只是函数调用?
此外,如果该函数调用位于另一个文件中,该进程是否能够调用它?
python ×3
apache-spark ×1
dataframe ×1
dictionary ×1
logging ×1
pickle ×1
python-3.x ×1
scala ×1
tkinter ×1
xml-parsing ×1