我已经安装了 python 2.5 和 PyQt 4.8.6。操作系统 - Windows Xp Sp2。我使用以下代码来填充 TreeWidget:
def updateTreeWidget(self, widget, results):
""" Updates the widget with given results """
widget.clear()
for item in results:
temp = QtGui.QTreeWidgetItem()
j = 0
for elem in item:
temp.setText(j , str(elem))
j += 1
widget.addTopLevelItem(temp)
for column in range(widget.columnCount()):
widget.resizeColumnToContents(column)
Run Code Online (Sandbox Code Playgroud)
它会在第二次使用时导致崩溃。如果我注释掉以下几行之一:
widget.addTopLevelItem(temp)
Run Code Online (Sandbox Code Playgroud)
或者
widget.clear()
Run Code Online (Sandbox Code Playgroud)
它可以毫无问题地工作。
我每 60 秒调用一次线程中的函数。这是 MyThread 类的定义。
class MyThread(threading.Thread):
def __init__(self, db, widget, function, script, parameter):
threading.Thread.__init__(self)
self.db = db
self.function = function
self.script = script
self.parameter …
Run Code Online (Sandbox Code Playgroud) 我正在尝试与 multiprocessing.Process 和 requests 并行运行多个 API 请求。我将要解析的 url 放入 JoinableQueue 实例中,并将内容放回到 Queue 实例中。我注意到将 response.content 放入队列会以某种方式阻止进程终止。
下面是只有 1 个进程的简化示例(Python 3.5):
import multiprocessing as mp
import queue
import requests
import time
class ChildProcess(mp.Process):
def __init__(self, q, qout):
super().__init__()
self.qin = qin
self.qout = qout
self.daemon = True
def run(self):
while True:
try:
url = self.qin.get(block=False)
r = requests.get(url, verify=False)
self.qout.put(r.content)
self.qin.task_done()
except queue.Empty:
break
except requests.exceptions.RequestException as e:
print(self.name, e)
self.qin.task_done()
print("Infinite loop terminates")
if __name__ == '__main__':
qin = mp.JoinableQueue()
qout …
Run Code Online (Sandbox Code Playgroud) 我想在带有Python3的Ubuntu上使用硒。我根据说明运行以下命令:
ubuntu:~$ sudo pip-3.2 install -U selenium
Downloading/unpacking selenium
Downloading selenium-2.37.2.tar.gz (2.6MB): 2.6MB downloaded
Running setup.py egg_info for package selenium
Installing collected packages: selenium
Running setup.py install for selenium
Successfully installed selenium
Cleaning up...
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试在python3中导入selenium模块时,出现错误:
@ubuntu:~$ python3
Python 3.2.5 (default, Sep 7 2013, 16:55:10)
[GCC 4.6.3] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import selenium
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named selenium
Run Code Online (Sandbox Code Playgroud)