Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #30518
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Subject | Re: QThread.terminate in Python 3 |
| Date | 2012-09-29 14:05 -0400 |
| Organization | > Bestiaria Support Staff < |
| References | <SNT106-W1816CD215F3BA3C4089A65B1810@phx.gbl> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.1647.1348941943.27098.python-list@python.org> (permalink) |
On Sat, 29 Sep 2012 06:34:00 +0430, Lee Harr <missive@hotmail.com>
declaimed the following in gmane.comp.python.general:
>
> Ok. Point taken.
>
> What I hear you saying is that once I use .terminate anything
> following that is indeterminate. It might work on my system
> and nowhere else. Even though it was working for me before,
> it was likely causing trouble elsewhere.
>
Even changing a line of code could potentially cause a problem (if
the terminate action takes place between a different set of Python
op-codes).
>
> So, I need another approach.
>
> The problem I am facing is that I want to run arbitrary
> (user-supplied) code in the other thread and need to be
> able to stop it at any time.
>
The cleanest, that I can visualize (though I can't suggest
implementation), is probably to run as an independent subprocess (or
maybe via multiprocess), with some sort of non-blocking (polled?) I/O
for results. You should be able to use OS-level operations to terminate
the independent process and ensure the system reclaims all associated
memory.
> It uses ctypes to raise an exception in the other thread.
> For the simple test case, at least, it works (for me).
>
> Is this any safer or more reliable than .terminate ?
>
Out of my experience; but if the exception is truly in the other
thread it should be a clean exit -- since the exception detection code
is part of the Python interpreter logic, it should be saving clean
states (after all, it it could leave a corrupt state, having exception
handlers won't help in recovery). Even better would be to wrap the
thread operation with an exception handler in which you can explicitly
perform any clean-up (or, at least, log the situation).
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: QThread.terminate in Python 3 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2012-09-29 14:05 -0400
csiph-web