简体   繁体   English

Python-将列表放入线程模块

[英]Python - Put a list in a threading module

I want to put a list into my threading script, but I am facing a problem. 我想在我的线程脚本中添加一个列表,但是我遇到了一个问题。

Contents of list file (example): 列表文件的内容(示例):

http://google.com
http://yahoo.com
http://bing.com
http://python.org

My script: 我的剧本:

import codecs
import threading
import sys
import requests
from time import time as timer
from timeout import timeout
import time

try:
    with codecs.open(sys.argv[1], mode='r', encoding='ascii', errors='ignore') as iiz:
        iiz=iiz.read().splitlines()
except IOError:
    pass

oz = list(iiz)
def nnn(url):
    hzz = {'param1': sys.argv[2], 'param2': sys.argv[3]}
    po = requests.post(url,data=hzz)
    if po:
            print("ok \n")

if __name__ == '__main__':
    threads = []
    for i in range(1):
        t = threading.Thread(target=nnn, args=(oz,))
        threads.append(t)
        t.start()

Can you please clarify what elaborate on exactly what you're trying to achieve. 您能否澄清一下您要实现的目标。

I'm guessing that you're trying to request urls to load into a web browser or the terminal... 我猜您正在尝试请求将网址加载到网络浏览器或终端中...

Also you shouldn't need to put the urls into a list because when you opened up the file containing the urls, it automatically sorted it into a list. 另外,您不需要将URL放入列表中,因为当您打开包含URL的文件时,它会自动将其分类到列表中。 So in other words, the contents in iiz are already in the list format. 因此,换句话说,iiz中的内容已经是列表格式。

Personally, I haven't worked much with the modules you're using (apart from time), but I'll try my best to help you and hopefully other users will try and help you too. 就个人而言,我与您正在使用的模块并没有做太多的工作(除了时间),但是我会尽力帮助您,希望其他用户也能为您提供帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM