Is this correct usage of linesfromfile, labels and threads?



  • I want to create a CSV that contains user data.
    I want o create a thread for each user.
    I want each thread to load one user (line) from the csv.
    Then I want it to go into an infinite loop.

    So I:
    Set thread number to the number of users I have - the number of lines in my csv.
    Set success number to negative 1.
    Set fail number to negative 1.
    Create a resource > linesfromfile > read only > use each line one time.
    Load my csv file.
    Use parse lines.
    Set label "begin loop".
    Do my work.
    And then use Move to label "begin loop" to repeat my work function.
    I want each thread to be one line from my csv and I want it to loop my work function forever.

    Attached is an example. 0_1499112080014_listfromfile-loop.xml

    Is that the correct method?

    Can I write to the csv file? Such as add the succeess count to each user's line? Or should that be done in a seperate file?

    Thank you.



  • I want my threads to loop forever but no matter what I do they eventually end. Sometimes with success and sometimes with error. How do I get them to loop forever.

    I've tried setting success and fail to -1.
    Wrapping everything in ignore errors.
    Wrapping everything in while 1==1.
    Setting a label at the begging and at end moving to label at start.

    Thanks.



  • @caplaz

    Is that the correct method?

    Yes, this will work.

    Can I write to the csv file?

    Yes, there is action called Write File(which also has append switch).

    Can also use csv_generate api for proper escaping.

    Action "Custom" and

    [[CSV_LINE]] = csv_generate(["a","b","c"],",")
    

    Or should that be done in a seperate file?

    Better use database, not csv

    I want my threads to loop forever but no matter what I do they eventually end. Sometimes with success and sometimes with error.

    If you have any failure during thread run, for eaxmple failed to load with proxy error, the thread will end. And as long as you set "use each line one time" to resource, it won't be used again.

    Ending with success is strange, probably, because you are using labels inside loops, 20 version has good explanation about this:

    There are two types of goto: long and short. Short move is performed if goto and label are located inside same block (has one parent). This type of move preserves execution history and script continues afterward. In other cases long move is performed, which clears execution history. Long move case is perfect if you are jumping on script start, but if you move inside loop, you must use another move to leave it, otherwise thread will stop with success message.

    Anyway, if you have some code, that may return error, just wrap it inside ignore errors action.
    You can also wrap whole list of actions that you want to do with account inside ignore errors block.
    Like this

    0_1500075786806_listfromfile-loop.xml


Log in to reply