On 01Aug2017 14:48, Daniel Bosah <dbo...@buffalo.edu> wrote:
I'm following an online tutorial about threading. This is the code I've
used so far:

In addition to the other replies, which mention the general computing "daemon" notion and the "python-daemon" library which aids making such python programs into well behaved daemons, I've got a couple of remarks about your code:

[...]
def threader():
   while True:
       worker = q.get()
       portscan(worker)
       q.task_done

task_done is a method. So "q.task_done()". Your code will parse and run but the method will not get called; "q.task_done" with no brackets just mentioned the method without running it (sometimes a program wants to talk about a method or function but not call it right now).

   t.daemon() = True # want it to be a daemon

The Thread.daemon is a property, not a method. So you set it like this:

   t.daemon = True

In the context of a thread, the daemon attribute implies that the daemon is a "worker" process, which does not need special shutdown. When your program ends, the Python runtime does not actually terminate until all _non_ damon Threads have finished. By marking a Thread as a daemon you're saying that its activity is not important after program exit. This is probably not the case for your tutorial task.

Like others, I recommend learning Python 3. It is broadly the same language but it is current.

Cheers,
Cameron Simpson <c...@cskk.id.au> (formerly c...@zip.com.au)
_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor

Reply via email to