简体   繁体   中英

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. So in other words, the contents in iiz are already in the list format.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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