Re: [Tutor] How to stop a specific thread in Python 2.7?
Thank you for the hint ! On Fri, Oct 04, 2024 at 09:17:19AM GMT, Cameron Simpson wrote: On 03Oct2024 22:12, Dan Ciprus (dciprus) wrote: I'd be interested too :-). Untested sketch: def make_thread(target, *a, E=None, **kw): ''' Make a new Event E and Thread T, pass `[E,*a]` as the target positional arguments. A shared preexisting Event may be supplied. Return a 2-tuple of `(T,E)`. ''' if E is None: E = Event() T = Thread(target=target, args=[E, *a], kwargs=kw) return T, E Something along those lines. Cheers, Cameron Simpson -- Dan Ciprus [ curl -L http://git.io/unix ] signature.asc Description: PGP signature -- https://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] How to stop a specific thread in Python 2.7?
On 03Oct2024 22:12, Dan Ciprus (dciprus) wrote: I'd be interested too :-). Untested sketch: def make_thread(target, *a, E=None, **kw): ''' Make a new Event E and Thread T, pass `[E,*a]` as the target positional arguments. A shared preexisting Event may be supplied. Return a 2-tuple of `(T,E)`. ''' if E is None: E = Event() T = Thread(target=target, args=[E, *a], kwargs=kw) return T, E Something along those lines. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] How to stop a specific thread in Python 2.7?
I'd be interested too :-). On Thu, Sep 26, 2024 at 03:34:05AM GMT, marc nicole via Python-list wrote: Could you show a python code example of this? On Thu, 26 Sept 2024, 03:08 Cameron Simpson, wrote: On 25Sep2024 22:56, marc nicole wrote: >How to create a per-thread event in Python 2.7? Every time you make a Thread, make an Event. Pass it to the thread worker function and keep it to hand for your use outside the thread. ___ Tutor maillist - tu...@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor -- https://mail.python.org/mailman/listinfo/python-list -- Dan Ciprus [ curl -L http://git.io/unix ] signature.asc Description: PGP signature -- https://mail.python.org/mailman/listinfo/python-list
Re: How to stop a specific thread in Python 2.7?
That's one of the "disadvantages" of threads: you cannot safely stop a thread. Of course you could try, but that's never a good idea. The reason for this is that threads share memory. They might be holding locks that, if killed, will never be unlocked. They might (partially) modify the shared state observed by other threads in such a way that it becomes unusable to other threads. So... if you want to kill a thread, I'm sorry to say this: you will have to bring down the whole process, there's really no other way, and that's not Python-specific, this is just the design of threads. On Wed, Sep 25, 2024 at 7:26 PM marc nicole via Python-list wrote: > > Hello guys, > > I want to know how to kill a specific running thread (say by its id) > > for now I run and kill a thread like the following: > # start thread > thread1 = threading.Thread(target= self.some_func(), args=( ...,), ) > thread1.start() > # kill the thread > event_thread1 = threading.Event() > event_thread1.set() > > I know that set() will kill all running threads, but if there was thread2 > as well and I want to kill only thread1? > > Thanks! > -- > https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: [Tutor] How to stop a specific thread in Python 2.7?
Could you show a python code example of this? On Thu, 26 Sept 2024, 03:08 Cameron Simpson, wrote: > On 25Sep2024 22:56, marc nicole wrote: > >How to create a per-thread event in Python 2.7? > > Every time you make a Thread, make an Event. Pass it to the thread > worker function and keep it to hand for your use outside the thread. > ___ > Tutor maillist - tu...@python.org > To unsubscribe or change subscription options: > https://mail.python.org/mailman/listinfo/tutor > -- https://mail.python.org/mailman/listinfo/python-list
Re: How to stop a specific thread in Python 2.7?
On 25Sep2024 22:56, marc nicole wrote: How to create a per-thread event in Python 2.7? Every time you make a Thread, make an Event. Pass it to the thread worker function and keep it to hand for your use outside the thread. -- https://mail.python.org/mailman/listinfo/python-list
Re: How to stop a specific thread in Python 2.7?
How to create a per-thread event in Python 2.7? On Wed, 25 Sept 2024, 22:47 Cameron Simpson via Python-list, < python-list@python.org> wrote: > On 25Sep2024 19:24, marc nicole wrote: > >I want to know how to kill a specific running thread (say by its id) > > > >for now I run and kill a thread like the following: > ># start thread > >thread1 = threading.Thread(target= self.some_func(), args=( ...,), ) > >thread1.start() > ># kill the thread > >event_thread1 = threading.Event() > >event_thread1.set() > > > >I know that set() will kill all running threads, but if there was thread2 > >as well and I want to kill only thread1? > > No, `set()` doesn't kill a thread at all. It sets the `Event`, and each > thread must be checking that event regularly, and quitting if it becomes > set. > > You just need a per-thred vent instead of a single Event for all the > threads. > > Cheers, > Cameron Simpson > -- > https://mail.python.org/mailman/listinfo/python-list > -- https://mail.python.org/mailman/listinfo/python-list
Re: How to stop a specific thread in Python 2.7?
On 25Sep2024 19:24, marc nicole wrote: I want to know how to kill a specific running thread (say by its id) for now I run and kill a thread like the following: # start thread thread1 = threading.Thread(target= self.some_func(), args=( ...,), ) thread1.start() # kill the thread event_thread1 = threading.Event() event_thread1.set() I know that set() will kill all running threads, but if there was thread2 as well and I want to kill only thread1? No, `set()` doesn't kill a thread at all. It sets the `Event`, and each thread must be checking that event regularly, and quitting if it becomes set. You just need a per-thred vent instead of a single Event for all the threads. Cheers, Cameron Simpson -- https://mail.python.org/mailman/listinfo/python-list
How to stop a specific thread in Python 2.7?
Hello guys, I want to know how to kill a specific running thread (say by its id) for now I run and kill a thread like the following: # start thread thread1 = threading.Thread(target= self.some_func(), args=( ...,), ) thread1.start() # kill the thread event_thread1 = threading.Event() event_thread1.set() I know that set() will kill all running threads, but if there was thread2 as well and I want to kill only thread1? Thanks! -- https://mail.python.org/mailman/listinfo/python-list
Re: stdout of child process as an input of another thread in Python?
Kevin Peterson writes: > I want to use the stdout of child process as an input of another thread, but > some how I am not able to read the stdout. Using Popen I have created a > child process and stdout of it I have redirected to PIPE (because I don't > want that to be printed on with my main process). Now using this > statement,"Line=Proc.stdout.readline()" I want to read stdout of child > process and I have to do operation on that. but somehow i am not able to read > from stdout of child process. > > Following is the code snapshot - > > Proc = Popen(["python.exe","filename.py"],stdout=PIPE) > > while True: > Line = Proc.stdout.readline() > print Line > > Here, > Filename.py(Child process) is continuously printing "Hello World!!" in place > of reading stdout of child process. Your description is not sufficiently clear: If "filename.py" is your child process, why should it read the stdout of the child process (i.e. itself). I suggest, you describe what "filename.py" (your child) does and what behavior you observe for the parent. -- https://mail.python.org/mailman/listinfo/python-list
stdout of child process as an input of another thread in Python?
Hi, I want to use the stdout of child process as an input of another thread, but some how I am not able to read the stdout. Using Popen I have created a child process and stdout of it I have redirected to PIPE (because I don't want that to be printed on with my main process). Now using this statement,"Line=Proc.stdout.readline()" I want to read stdout of child process and I have to do operation on that. but somehow i am not able to read from stdout of child process. Following is the code snapshot - Proc = Popen(["python.exe","filename.py"],stdout=PIPE) while True: Line = Proc.stdout.readline() print Line Here, Filename.py(Child process) is continuously printing "Hello World!!" in place of reading stdout of child process. Thanks, Kevin Peterson -- https://mail.python.org/mailman/listinfo/python-list
Re: How to prevent from race conditions to share data between many process and thread in python
mars a écrit : > I use TurboGears to do some web service. TurboGears use cherrypy. When > web browser access this site, the cherrypy will call my python > program. So my program looks like a lib. When web browser access the > site, the http server will fock a process or gerenate a thread. I need > share some data or operate some files. How can I prevent from race > conditions. Is there any way can I lock this. > Thank you in advance! See in the cookbook: http://aspn.activestate.com/ASPN/search?query=locking&x=0&y=0§ion=PYTHONCKBK&type=Subsection And test/choose one solution... http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/252495 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203 ... A+ Laurent. -- http://mail.python.org/mailman/listinfo/python-list
Re: How to prevent from race conditions to share data between many process and thread in python
En Tue, 06 Feb 2007 08:49:51 -0300, Diez B. Roggisch <[EMAIL PROTECTED]> escribió: > mars wrote: > >> On 2月6日, 下午6时14分, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >>> mars wrote: >>> > I use TurboGears to do some web service. TurboGears use cherrypy. >>> When >>> > web browser access this site, the cherrypy will call my python >>> > program. So my program looks like a lib. When web browser access the >>> > site, the http server will fock a process or gerenate a thread. I >>> need >>> > share some data or operate some files. How can I prevent from race >>> > conditions. Is there any way can I lock this. >>> > Thank you in advance! >>> >>> There are the Lock and RLock objects available in the module threading. >> >> Can this also lock mutil-process? > > No. You have to use the syncronization tools provided by your OS in that case; maybe using a locked file (fcntl). -- Gabriel Genellina -- http://mail.python.org/mailman/listinfo/python-list
Re: How to prevent from race conditions to share data between many process and thread in python
mars wrote: > On 2月6日, 下午6时14分, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: >> mars wrote: >> > I use TurboGears to do some web service. TurboGears use cherrypy. When >> > web browser access this site, the cherrypy will call my python >> > program. So my program looks like a lib. When web browser access the >> > site, the http server will fock a process or gerenate a thread. I need >> > share some data or operate some files. How can I prevent from race >> > conditions. Is there any way can I lock this. >> > Thank you in advance! >> >> There are the Lock and RLock objects available in the module threading. >> >> Diez > > Can this also lock mutil-process? No. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: How to prevent from race conditions to share data between many process and thread in python
On 2月6日, 下午6时14分, "Diez B. Roggisch" <[EMAIL PROTECTED]> wrote: > mars wrote: > > I use TurboGears to do some web service. TurboGears use cherrypy. When > > web browser access this site, the cherrypy will call my python > > program. So my program looks like a lib. When web browser access the > > site, the http server will fock a process or gerenate a thread. I need > > share some data or operate some files. How can I prevent from race > > conditions. Is there any way can I lock this. > > Thank you in advance! > > There are the Lock and RLock objects available in the module threading. > > Diez Can this also lock mutil-process? -- http://mail.python.org/mailman/listinfo/python-list
Re: How to prevent from race conditions to share data between many process and thread in python
mars wrote: > I use TurboGears to do some web service. TurboGears use cherrypy. When > web browser access this site, the cherrypy will call my python > program. So my program looks like a lib. When web browser access the > site, the http server will fock a process or gerenate a thread. I need > share some data or operate some files. How can I prevent from race > conditions. Is there any way can I lock this. > Thank you in advance! There are the Lock and RLock objects available in the module threading. Diez -- http://mail.python.org/mailman/listinfo/python-list
How to prevent from race conditions to share data between many process and thread in python
I use TurboGears to do some web service. TurboGears use cherrypy. When web browser access this site, the cherrypy will call my python program. So my program looks like a lib. When web browser access the site, the http server will fock a process or gerenate a thread. I need share some data or operate some files. How can I prevent from race conditions. Is there any way can I lock this. Thank you in advance! -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread in python
Hi ! Look the smart/fun use of threads make by http://candygram.sourceforge.net It's good for to know... @-salutations -- Michel Claveau -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread in python
In article <[EMAIL PROTECTED]>, Steve Holden <[EMAIL PROTECTED]> wrote: > >http://starship.python.net/crew/aahz/OSCON2001/index.html Thanks! But while that's still good (for the code, if nothing else), it ought to be at least supplemented with http://heather.cs.ucdavis.edu/~matloff/Python/PyThreads.pdf -- Aahz ([EMAIL PROTECTED]) <*> http://www.pythoncraft.com/ "The joy of coding Python should be in seeing short, concise, readable classes that express a lot of action in a small amount of clear code -- not in reams of trivial code that bores the reader to death." --GvR -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread in python
Ah! I forgot about this link the slideshow is very informative. -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread in python
Kartic wrote: [EMAIL PROTECTED] wrote: Hello, is any one knows websites which give a python thread tutorial ? Sincerely Yours, Pujo Aji Pujo Aji, I have not come across a tutorial but found this link rather helpful - http://www.faqts.com/knowledge_base/index.phtml/fid/263 - to get started. Also, there are good recipes in ASPN - http://aspn.activestate.com/ASPN/Cookbook/Python?kwd=Threads And last but not least, the chapter on Threads in Python Standard Library by Fredrik Lundh - http://effbot.org/zone/books.htm Thanks, -Kartic http://starship.python.net/crew/aahz/OSCON2001/index.html regards Steve -- Meet the Python developers and your c.l.py favorites March 23-25 Come to PyCon DC 2005 http://www.pycon.org/ Steve Holden http://www.holdenweb.com/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Thread in python
[EMAIL PROTECTED] wrote: > Hello, is any one knows websites which give a python thread tutorial ? > > Sincerely Yours, > Pujo Aji Pujo Aji, I have not come across a tutorial but found this link rather helpful - http://www.faqts.com/knowledge_base/index.phtml/fid/263 - to get started. Also, there are good recipes in ASPN - http://aspn.activestate.com/ASPN/Cookbook/Python?kwd=Threads And last but not least, the chapter on Threads in Python Standard Library by Fredrik Lundh - http://effbot.org/zone/books.htm Thanks, -Kartic -- http://mail.python.org/mailman/listinfo/python-list
Thread in python
Hello, is any one knows websites which give a python thread tutorial ? Sincerely Yours, Pujo Aji -- http://mail.python.org/mailman/listinfo/python-list