Search code examples
pythonmultithreadinggoto

When I use the goto module,it works but I got an error: Exception TypeError


The goto module I install is form:the module I installed

Here is the error:

Exception TypeError: "argument of type 'NoneType' is not iterable" in ignored

Here is the code:

from goto import goto,label

for i in range(1,10) :
    print i
    if i == 9 :
        goto .say
    else:
        pass

label .say
print "find 9"

So Here is my code need to use goto:

#coding = utf-8

import requests
import threading
from goto import goto,label

nums = ['1','2','3','4','5','6','7','8','9','0']
schars = ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
chars = nums + schars

xml = ".xml"
root = "192.168.1.1:1900"
threads = 500
sem = threading.Semaphore(threads)

def get200(url):
    res = requests.get(url)
    if res.status_code == 200 :
        print url

def match(filename,length) :
    if len(filename) <= (length +1):
        for char in chars :
            label.retry
            if sem.acquire :
                filename += char
                t = threading.Thread(target = get200,args = (root + filename + xml))
                t.start()
                sem.release()
                match(filename,length)
            else:
                goto.retry

    else :
        return

match('/',6)

Solution

  • You don't need goto. Period. Just learn to use Python properly.

    for i in range(1,10) :
        print i
        if i == 9 :
            print "find 9"
            break 
    

    Applied to your actual code, the solution is almost the same:

    for char in chars :
        while True:
            if sem.acquire :
                filename += char
                t = threading.Thread(target=get200, args=(root + filename + xml))
                t.start()
                sem.release()
                match(filename,length)
                break
    

    Which can be made even simpler:

    for char in chars :
        while not sem.acquire:
            continue
        filename += char
        t = threading.Thread(target= get200, args=(root + filename + xml))
        t.start()
        sem.release()
        match(filename,length)