Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #52452

Re: multithreading in python

From Dave Angel <davea@davea.name>
Subject Re: multithreading in python
Date 2013-08-13 11:22 +0000
References <dac9bb94-a1e2-410b-b925-445a2c8b66a0@googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.530.1376392996.1251.python-list@python.org> (permalink)

Show all headers | View raw


samaneh.yahyapour@gmail.com wrote:

> hi 
> my program work by 4 thread but when i use more thread it terminates
>
> 

I simplified your code so anybody could run it, and tested it inside
Komodo IDE, on Python 2.7

#!/usr/bin/env python


import sys
import os
import time
import threading

class MyClass():

    def __init__(self):
        i = 0
        while i<10:
            work = WorkClass(i)
            thread1 = threading.Thread(target=work.item_thread)
            thread1.start()
            i = i+1
            time.sleep(0.01)

class WorkClass():
    def __init__(self, parm):
        self.parm = str(parm)
    def item_thread(self):
        print "beginning thread", self.parm
        for filename in os.listdir("."):
            data =  "thread " +  self.parm + " filename " + filename + "\n"
            print data
            time.sleep(0.5)
        print "ENDDDDDDDDDDDDDDDDDDDDDDDDDDDD " + self.parm

x = MyClass()         
print "Finishing main thread"

When the
-- 
Signature file not found

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

multithreading in python samaneh.yahyapour@gmail.com - 2013-08-13 01:06 -0700
  Re: multithreading in python Steven D'Aprano <steve@pearwood.info> - 2013-08-13 08:38 +0000
  Re: multithreading in python Dave Angel <davea@davea.name> - 2013-08-13 11:22 +0000
  Re: multithreading in python Dave Angel <davea@davea.name> - 2013-08-13 11:40 +0000
  Re: multithreading in python Terry Reedy <tjreedy@udel.edu> - 2013-08-13 11:51 -0400

csiph-web