Interrupted system call error

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Interrupted system call error

Robert Unguran
Hi

I have a client-server application using Envisage framework, I'm using
threads to handle the connection, here is a token from the code

....
         SocketServer.TCPServer.allow_reuse_address = True
         self.server = TCPFactory( ( HOST, PORT ), TCPRequestHandler,
self.application)

         self.server_thread = threading.Thread( target =
self.server.serve_forever )

         self.server_thread.setDaemon( True )
         self.server_thread.start()

     class TCPFactory( SocketServer.ThreadingTCPServer ):
         def __init__( self, server_address, RequestHandlerClass,
application ):
             SocketServer.ThreadingTCPServer.__init__( self,
server_address, RequestHandlerClass )
             self.application = application

     class TCPRequestHandler( SocketServer.BaseRequestHandler ):
         """"""
         def setup( self ):
             .....

In the envisage framework I call the `open_file( )` function, which give
us a popup window, but when this window appear than I'm receiving the
following error

Exception in thread Thread-2:
     Traceback (most recent call last):
       File "/usr/lib/python2.7/threading.py", line 551, in
__bootstrap_inner
         self.run()
       File "/usr/lib/python2.7/threading.py", line 504, in run
         self.__target(*self.__args, **self.__kwargs)
       File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
         r, w, e = select.select([self], [], [], poll_interval)
     error: (4, 'Interrupted system call')

How can I handle this error?


Regards,
Robert

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Interrupted system call error

Robert Kern
On Fri, Nov 16, 2012 at 10:20 AM, Robert Unguran <[hidden email]> wrote:

> Hi
>
> I have a client-server application using Envisage framework, I'm using
> threads to handle the connection, here is a token from the code
>
> ....
>          SocketServer.TCPServer.allow_reuse_address = True
>          self.server = TCPFactory( ( HOST, PORT ), TCPRequestHandler,
> self.application)
>
>          self.server_thread = threading.Thread( target =
> self.server.serve_forever )
>
>          self.server_thread.setDaemon( True )
>          self.server_thread.start()
>
>      class TCPFactory( SocketServer.ThreadingTCPServer ):
>          def __init__( self, server_address, RequestHandlerClass,
> application ):
>              SocketServer.ThreadingTCPServer.__init__( self,
> server_address, RequestHandlerClass )
>              self.application = application
>
>      class TCPRequestHandler( SocketServer.BaseRequestHandler ):
>          """"""
>          def setup( self ):
>              .....
>
> In the envisage framework I call the `open_file( )` function, which give
> us a popup window, but when this window appear than I'm receiving the
> following error
>
> Exception in thread Thread-2:
>      Traceback (most recent call last):
>        File "/usr/lib/python2.7/threading.py", line 551, in
> __bootstrap_inner
>          self.run()
>        File "/usr/lib/python2.7/threading.py", line 504, in run
>          self.__target(*self.__args, **self.__kwargs)
>        File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
>          r, w, e = select.select([self], [], [], poll_interval)
>      error: (4, 'Interrupted system call')
>
> How can I handle this error?

What GUI toolkit are you using? Some GUI toolkits (I have noticed this
with Qt especially) seem to do something with signals that will
interrupt system calls like this. It's not easy to find out what
signal is doing the interrupting. If you can find the signal at fault,
you can tell the process to restart interrupted system calls with
`signal.siginterrupt(signum, False)` at the beginning of your main():

  http://docs.python.org/2/library/signal#signal.siginterrupt

You may even try doing that to all available signals.

--
Robert Kern
Enthought
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Interrupted system call error

Robert Unguran
On 11/16/2012 11:45 AM, Robert Kern wrote:

> On Fri, Nov 16, 2012 at 10:20 AM, Robert Unguran <[hidden email]> wrote:
>> Hi
>>
>> I have a client-server application using Envisage framework, I'm using
>> threads to handle the connection, here is a token from the code
>>
>> ....
>>           SocketServer.TCPServer.allow_reuse_address = True
>>           self.server = TCPFactory( ( HOST, PORT ), TCPRequestHandler,
>> self.application)
>>
>>           self.server_thread = threading.Thread( target =
>> self.server.serve_forever )
>>
>>           self.server_thread.setDaemon( True )
>>           self.server_thread.start()
>>
>>       class TCPFactory( SocketServer.ThreadingTCPServer ):
>>           def __init__( self, server_address, RequestHandlerClass,
>> application ):
>>               SocketServer.ThreadingTCPServer.__init__( self,
>> server_address, RequestHandlerClass )
>>               self.application = application
>>
>>       class TCPRequestHandler( SocketServer.BaseRequestHandler ):
>>           """"""
>>           def setup( self ):
>>               .....
>>
>> In the envisage framework I call the `open_file( )` function, which give
>> us a popup window, but when this window appear than I'm receiving the
>> following error
>>
>> Exception in thread Thread-2:
>>       Traceback (most recent call last):
>>         File "/usr/lib/python2.7/threading.py", line 551, in
>> __bootstrap_inner
>>           self.run()
>>         File "/usr/lib/python2.7/threading.py", line 504, in run
>>           self.__target(*self.__args, **self.__kwargs)
>>         File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
>>           r, w, e = select.select([self], [], [], poll_interval)
>>       error: (4, 'Interrupted system call')
>>
>> How can I handle this error?
> What GUI toolkit are you using? Some GUI toolkits (I have noticed this
> with Qt especially) seem to do something with signals that will
> interrupt system calls like this. It's not easy to find out what
> signal is doing the interrupting. If you can find the signal at fault,
> you can tell the process to restart interrupted system calls with
> `signal.siginterrupt(signum, False)` at the beginning of your main():
>
>    http://docs.python.org/2/library/signal#signal.siginterrupt
>
> You may even try doing that to all available signals.
>
> --
> Robert Kern
> Enthought
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev
Thanks for your answer,

The problem is occur when I'm using qt, with wx everything is working fine.

Regards,
Robert
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Interrupted system call error

Robert Unguran
In reply to this post by Robert Kern
On 11/16/2012 11:45 AM, Robert Kern wrote:
> signal.siginterrupt(signum, False)
I tried the following code

def handleSigTERM( signum, stack ):
     print 'Caught signal %s, ignoring.' % ( str( signum ) )

def main():
     """ Run the application. """
     for i in [x for x in dir( signal ) if x.startswith( "SIG" )]:
         try:
             signum = getattr( signal, i )
             #print signum
             signal.signal( signum, handleSigTERM )
         except :
             print "Skipping %s" % i


But I'm getting the same error:

Skipping SIGKILL
Skipping SIGSTOP
Skipping SIG_DFL
Exception in thread Thread-3:
Traceback (most recent call last):
   File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
     self.run()
   File "/usr/lib/python2.7/threading.py", line 504, in run
     self.__target(*self.__args, **self.__kwargs)
   File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
     r, w, e = select.select([self], [], [], poll_interval)
error: (4, 'Interrupted system call')
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Interrupted system call error

Robert Kern
Defining a do-nothing handler does not change whether system calls get
restarted after the interruption. Use signal.siginterrupt() like I
said.

On Fri, Nov 16, 2012 at 1:16 PM, Robert Unguran <[hidden email]> wrote:

> On 11/16/2012 11:45 AM, Robert Kern wrote:
>> signal.siginterrupt(signum, False)
> I tried the following code
>
> def handleSigTERM( signum, stack ):
>      print 'Caught signal %s, ignoring.' % ( str( signum ) )
>
> def main():
>      """ Run the application. """
>      for i in [x for x in dir( signal ) if x.startswith( "SIG" )]:
>          try:
>              signum = getattr( signal, i )
>              #print signum
>              signal.signal( signum, handleSigTERM )
>          except :
>              print "Skipping %s" % i
>
>
> But I'm getting the same error:
>
> Skipping SIGKILL
> Skipping SIGSTOP
> Skipping SIG_DFL
> Exception in thread Thread-3:
> Traceback (most recent call last):
>    File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
>      self.run()
>    File "/usr/lib/python2.7/threading.py", line 504, in run
>      self.__target(*self.__args, **self.__kwargs)
>    File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
>      r, w, e = select.select([self], [], [], poll_interval)
> error: (4, 'Interrupted system call')
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev



--
Robert Kern
Enthought
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Interrupted system call error

Robert Unguran
I also tried the signal.siginterrupt without success

for i in [x for x in dir( signal ) if x.startswith( "SIG" )]:
         try:
             signum = getattr( signal, i )
             signal.siginterrupt( signum, False )
         except :
             print "Skipping %s" % i


On 11/16/2012 02:21 PM, Robert Kern wrote:

> Defining a do-nothing handler does not change whether system calls get
> restarted after the interruption. Use signal.siginterrupt() like I
> said.
>
> On Fri, Nov 16, 2012 at 1:16 PM, Robert Unguran <[hidden email]> wrote:
>> On 11/16/2012 11:45 AM, Robert Kern wrote:
>>> signal.siginterrupt(signum, False)
>> I tried the following code
>>
>> def handleSigTERM( signum, stack ):
>>       print 'Caught signal %s, ignoring.' % ( str( signum ) )
>>
>> def main():
>>       """ Run the application. """
>>       for i in [x for x in dir( signal ) if x.startswith( "SIG" )]:
>>           try:
>>               signum = getattr( signal, i )
>>               #print signum
>>               signal.signal( signum, handleSigTERM )
>>           except :
>>               print "Skipping %s" % i
>>
>>
>> But I'm getting the same error:
>>
>> Skipping SIGKILL
>> Skipping SIGSTOP
>> Skipping SIG_DFL
>> Exception in thread Thread-3:
>> Traceback (most recent call last):
>>     File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
>>       self.run()
>>     File "/usr/lib/python2.7/threading.py", line 504, in run
>>       self.__target(*self.__args, **self.__kwargs)
>>     File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
>>       r, w, e = select.select([self], [], [], poll_interval)
>> error: (4, 'Interrupted system call')
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
>

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Interrupted system call error

Robert Kern
In that case, the workaround is to wrap the select.select() call with
a `try: except select.error, e:` that will retry the call if e.args[0]
== errno.EINTR. See here for a similar problem in IPython and 0MQ:

https://github.com/dovf/jsonrpc2-zeromq-python/commit/fb0b823c3e3ca5228e908a57d4c3f2ccffa32ea5

On Fri, Nov 16, 2012 at 1:34 PM, Robert Unguran <[hidden email]> wrote:

> I also tried the signal.siginterrupt without success
>
> for i in [x for x in dir( signal ) if x.startswith( "SIG" )]:
>          try:
>              signum = getattr( signal, i )
>              signal.siginterrupt( signum, False )
>          except :
>              print "Skipping %s" % i
>
>
> On 11/16/2012 02:21 PM, Robert Kern wrote:
>> Defining a do-nothing handler does not change whether system calls get
>> restarted after the interruption. Use signal.siginterrupt() like I
>> said.
>>
>> On Fri, Nov 16, 2012 at 1:16 PM, Robert Unguran <[hidden email]> wrote:
>>> On 11/16/2012 11:45 AM, Robert Kern wrote:
>>>> signal.siginterrupt(signum, False)
>>> I tried the following code
>>>
>>> def handleSigTERM( signum, stack ):
>>>       print 'Caught signal %s, ignoring.' % ( str( signum ) )
>>>
>>> def main():
>>>       """ Run the application. """
>>>       for i in [x for x in dir( signal ) if x.startswith( "SIG" )]:
>>>           try:
>>>               signum = getattr( signal, i )
>>>               #print signum
>>>               signal.signal( signum, handleSigTERM )
>>>           except :
>>>               print "Skipping %s" % i
>>>
>>>
>>> But I'm getting the same error:
>>>
>>> Skipping SIGKILL
>>> Skipping SIGSTOP
>>> Skipping SIG_DFL
>>> Exception in thread Thread-3:
>>> Traceback (most recent call last):
>>>     File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
>>>       self.run()
>>>     File "/usr/lib/python2.7/threading.py", line 504, in run
>>>       self.__target(*self.__args, **self.__kwargs)
>>>     File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
>>>       r, w, e = select.select([self], [], [], poll_interval)
>>> error: (4, 'Interrupted system call')
>>> _______________________________________________
>>> Enthought-Dev mailing list
>>> [hidden email]
>>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>
>>
>
> _______________________________________________
> Enthought-Dev mailing list
> [hidden email]
> https://mail.enthought.com/mailman/listinfo/enthought-dev



--
Robert Kern
Enthought
_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev
Reply | Threaded
Open this post in threaded view
|

Re: Interrupted system call error

Robert Unguran
Thanks, it's working great.

On 11/16/2012 02:41 PM, Robert Kern wrote:

> In that case, the workaround is to wrap the select.select() call with
> a `try: except select.error, e:` that will retry the call if e.args[0]
> == errno.EINTR. See here for a similar problem in IPython and 0MQ:
>
> https://github.com/dovf/jsonrpc2-zeromq-python/commit/fb0b823c3e3ca5228e908a57d4c3f2ccffa32ea5
>
> On Fri, Nov 16, 2012 at 1:34 PM, Robert Unguran <[hidden email]> wrote:
>> I also tried the signal.siginterrupt without success
>>
>> for i in [x for x in dir( signal ) if x.startswith( "SIG" )]:
>>           try:
>>               signum = getattr( signal, i )
>>               signal.siginterrupt( signum, False )
>>           except :
>>               print "Skipping %s" % i
>>
>>
>> On 11/16/2012 02:21 PM, Robert Kern wrote:
>>> Defining a do-nothing handler does not change whether system calls get
>>> restarted after the interruption. Use signal.siginterrupt() like I
>>> said.
>>>
>>> On Fri, Nov 16, 2012 at 1:16 PM, Robert Unguran <[hidden email]> wrote:
>>>> On 11/16/2012 11:45 AM, Robert Kern wrote:
>>>>> signal.siginterrupt(signum, False)
>>>> I tried the following code
>>>>
>>>> def handleSigTERM( signum, stack ):
>>>>        print 'Caught signal %s, ignoring.' % ( str( signum ) )
>>>>
>>>> def main():
>>>>        """ Run the application. """
>>>>        for i in [x for x in dir( signal ) if x.startswith( "SIG" )]:
>>>>            try:
>>>>                signum = getattr( signal, i )
>>>>                #print signum
>>>>                signal.signal( signum, handleSigTERM )
>>>>            except :
>>>>                print "Skipping %s" % i
>>>>
>>>>
>>>> But I'm getting the same error:
>>>>
>>>> Skipping SIGKILL
>>>> Skipping SIGSTOP
>>>> Skipping SIG_DFL
>>>> Exception in thread Thread-3:
>>>> Traceback (most recent call last):
>>>>      File "/usr/lib/python2.7/threading.py", line 551, in __bootstrap_inner
>>>>        self.run()
>>>>      File "/usr/lib/python2.7/threading.py", line 504, in run
>>>>        self.__target(*self.__args, **self.__kwargs)
>>>>      File "/usr/lib/python2.7/SocketServer.py", line 225, in serve_forever
>>>>        r, w, e = select.select([self], [], [], poll_interval)
>>>> error: (4, 'Interrupted system call')
>>>> _______________________________________________
>>>> Enthought-Dev mailing list
>>>> [hidden email]
>>>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>>>
>> _______________________________________________
>> Enthought-Dev mailing list
>> [hidden email]
>> https://mail.enthought.com/mailman/listinfo/enthought-dev
>
>

_______________________________________________
Enthought-Dev mailing list
[hidden email]
https://mail.enthought.com/mailman/listinfo/enthought-dev