Interrput a thread

Diez B. Roggisch deets at web.de
Mon Jan 3 17:57:17 EST 2011


gervaz <gervaz at gmail.com> writes:

> On 3 Gen, 22:17, Adam Skutt <ask... at gmail.com> wrote:
>> On Jan 3, 4:06 pm, Jean-Paul Calderone <calderone.jeanp... at gmail.com>
>> wrote:
>>
>>
>>
>> > > Multiple processes, ok, but then regarding processes' interruption
>> > > there will be the same problems pointed out by using threads?
>>
>> > No.  Processes can be terminated easily on all major platforms.  See
>> > `os.kill`.
>>
>> Yes, but that's not the whole story, now is it?  It's certainly much
>> more reliable and easier to kill a process.  It's not any easier to do
>> it and retain defined behavior, depending on exactly what you're
>> doing.  For example, if you kill it while it's in the middle of
>> updating shared memory, you can potentially incur undefined behavior
>> on the part of any process that can also access shared memory.
>>
>> In short, taking a program that uses threads and shared state and
>> simply replacing the threads with processes will likely not gain you a
>> thing.  It entirely depends on what those threads are doing and how
>> they do it.
>>
>> Adam
>
> As per the py3.1 documentation, os.kill is only available in the Unix
> os. Regarding the case pointed out by Adam I think the best way to
> deal with it is to create a critical section so that the shared memory
> will be updated in an atomic fashion. Btw it would be useful to take a
> look at some actual code/documentation in order to understand how
> others dealt with the problem...

There is the multiprocessing module. It's a good start, and works
cross-platform.

Diez



More information about the Python-list mailing list