Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The <code>thread.start_new_thread</code> function is really low-level and doesn't give you a lot of control. Take a look at the <code>threading</code> module, more specifically the <code>Thread</code> class: <a href="http://docs.python.org/2/library/threading.html#thread-objects" rel="nofollow">http://docs.python.org/2/library/threading.html#thread-objects</a></p> <p>You then want to replace the last 2 lines of your script with:</p> <pre><code># This line should be at the top of your file, obviously :p from threading import Thread threads = [] for i in sites: t = Thread(target=ftpconnect, args=[i]) threads.append(t) t.start() # Wait for all the threads to complete before exiting the program. for t in threads: t.join() </code></pre> <p>Your code was failing, by the way, because in your <code>for</code> loop, you were calling <code>ftpconnect(i)</code>, waiting for it to complete, and <em>then</em> trying to use its return value (that is, <code>None</code>) to start a new thread, which obviously doesn't work.</p> <p>In general, starting a thread is done by giving it a callable object (function/method -- you want the callable object, <em>not</em> the result of a call -- <code>my_function</code>, not <code>my_function()</code>), and optional arguments to give the callable object (in our case, <code>[i]</code> because <code>ftpconnect</code> takes one positional argument and you want it to be <code>i</code>), and then calling the <code>Thread</code> object's <code>start</code> method.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload