waitForProcess: sytem call interrupted

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

waitForProcess: sytem call interrupted

Joel Reymont
Folks,

My program frequently quites (I think) after this message:

waitForProcess: sytem call interrupted

I think it has to do with my killing the thread that calls connectTo,  
after a certain timeout. Is there a way to catch this exception so  
that the program does not crash?

My code looks like this:

connect :: HostName -> Int -> EngineState ()
connect host port =
     do w <- get
        let secs = timeout_seconds w
        x <- liftIOTrap $ timeout secs $ connect_ host port
        let h = case x of (Right x') -> x'
        trace "Connection established"
...

timeout :: forall a.Show a => Int -> IO a -> IO (Either String a)
timeout secs fun =
     do resultVar <- newEmptyMVar
        threadId <- forkIO $
                    do result <- try fun
                       let x = case result of
                                 Right a -> Right a
                                 Left b -> Left (fromIOError b)
                       trace_ $ "timeout: " ++ show x
                       putMVar resultVar x
        forkIO $ do threadDelay (secs * 1000000)
                    putMVar resultVar (Left "Timeout")
        maybeResult <- takeMVar resultVar
        case maybeResult
             of (Right result) -> return (Right result)
                (Left result) -> do killThread threadId
                                    return (Left result)

and

fromIOError err = ioeGetErrorString err

liftIOTrap :: IO a -> EngineState a
liftIOTrap io =
     do mx <- liftIO (do x <- io
                         return (return x)
                                    `catchError`
                                    (\e -> return (throwError
                                                   (fromIOError e))))
        mx


        Thanks, Joel

--
http://wagerlabs.com/





_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: waitForProcess: sytem call interrupted

Joel Reymont
The thing is that I'm launching threads, not processes. The message  
is printed by runhaskell now that I think about it.

On Nov 16, 2005, at 1:54 AM, Donald Bruce Stewart wrote:

> I've been getting this in lambdabot with waitForProcess since 6.4.1 (I
> think). Seems harmless though (I think). Try catching the exception.
>
>     Control.Exception.catch (waitForProcess pid)
>                             (\_ -> return ExitSuccess) -- so just  
> fake success

--
http://wagerlabs.com/





_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

Re: waitForProcess: sytem call interrupted

Joel Reymont
In reply to this post by Joel Reymont
I think runhaskell reports that when the program has crashed  
violently with a segmentation violation.

On Nov 16, 2005, at 1:54 AM, Donald Bruce Stewart wrote:

> I've been getting this in lambdabot with waitForProcess since 6.4.1 (I
> think). Seems harmless though (I think). Try catching the exception.
>
>     Control.Exception.catch (waitForProcess pid)
>                             (\_ -> return ExitSuccess) -- so just  
> fake success

--
http://wagerlabs.com/





_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|

RE: waitForProcess: sytem call interrupted

Simon Marlow
In reply to this post by Joel Reymont
On 16 November 2005 11:26, Joel Reymont wrote:

> I think runhaskell reports that when the program has crashed
> violently with a segmentation violation.

It does, and that's a bug.  I fixed it last week.

Cheers,
        Simon

>
> On Nov 16, 2005, at 1:54 AM, Donald Bruce Stewart wrote:
>
>> I've been getting this in lambdabot with waitForProcess since 6.4.1
>> (I think). Seems harmless though (I think). Try catching the
>> exception.
>>
>>     Control.Exception.catch (waitForProcess pid)
>>                             (\_ -> return ExitSuccess) -- so just
>> fake success
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe