multithreading - ReCreating threads in python -


i'm using following template recreate threads need run infinity. want know if template scalable in terms of memory. threaded destroyed properly?

import threading import time  class alazythread(threading.thread):      def __init__(self):         threading.thread.__init__(self)      def run(self):         time.sleep(10)         print "i don not want work :("  class aworkerthread(threading.thread):      def __init__(self):         threading.thread.__init__(self)      def run(self):         time.sleep(1)         print "i want work!!!!!!!"  threada = alazythread() threada.start() threadb = aworkerthread() threadb.start()  while true:      if not (threada.isalive()):         threada = alazythread()         threada.start()      if not (threadb.isalive()):         threadb = aworkerthread()         threadb.start() 

the thing bother me following picture taking in eclipse show debug info, , seems thread stacking it.

thread counts

  1. i see nothing wrong image. there's main thread , 2 threads created (according code, 3 threads supposed running @ time)

  2. like other python objects, threads garbage collected when they're not used; e.g. in main while cycle, when instantiate class (let's alazythread), old threada value destroyed (maybe not @ point, shortly after)

  3. the main while cycle, use sleep (e.g. time.sleep(1)), otherwise consume processor, uselessly checking if other threads running.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -