From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by yquem.inria.fr (Postfix) with ESMTP id 6C4F2BB83 for ; Thu, 6 Jul 2006 01:24:21 +0200 (CEST) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by concorde.inria.fr (8.13.6/8.13.6) with ESMTP id k65NOMbR032337 for ; Thu, 6 Jul 2006 01:24:22 +0200 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id BAA05359 for ; Thu, 6 Jul 2006 01:24:21 +0200 (MET DST) Received: from mz2.forethought.net (mzpi4.forethought.net [216.241.36.13]) by nez-perce.inria.fr (8.13.6/8.13.6) with ESMTP id k65NOJQc015140 (version=TLSv1/SSLv3 cipher=EDH-RSA-DES-CBC3-SHA bits=168 verify=NO) for ; Thu, 6 Jul 2006 01:24:21 +0200 Received: from [216.241.35.41] (helo=[10.0.0.2]) by mz2.forethought.net with esmtp (Exim 4.51) id 1FyGj5-0007VH-RL for caml-list@inria.fr; Wed, 05 Jul 2006 17:24:11 -0600 Message-ID: <44AC4A46.3070105@gushee.net> Date: Wed, 05 Jul 2006 17:24:54 -0600 From: Matt Gushee User-Agent: Thunderbird 1.5.0.4 (X11/20060615) MIME-Version: 1.0 To: caml-list@inria.fr Subject: Re: [Caml-list] LablGTK app maxes out CPU References: <44AAB3B3.6000807@gushee.net> <20060704191216.GA15888@localhost> <44AAC8EE.1060805@gushee.net> <20060704202117.GB15987@localhost> In-Reply-To: <20060704202117.GB15987@localhost> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Miltered: at concorde with ID 44AC4A26.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 44AC4A23.001 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; lablgtk:01 unix:01 nonblock:01 gtk:01 lablgtk:01 buf:01 buf:01 non-blocking:01 unix:01 increments:98 wrote:01 caml-list:01 exceptions:01 len:02 len:02 X-Spam-Checker-Version: SpamAssassin 3.0.3 (2005-04-27) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.3 Eric Cooper wrote: >> That's how it was originally. But if you look again at my code, you can see that the version with Unix.O_NONBLOCK is commented out. That's because on one of my machines (the one with a newer version of GTK and LablGTK, I believe), I got exceptions every time the program tried to read the input. > > Right, me too. I use code like this to read from the channel inside > the watcher: > > let try_read chan ~buf ~pos ~len = > try Some (Glib.Io.read chan ~buf ~pos ~len) > with Glib.GError "g_io_channel_read: G_IO_ERROR_AGAIN" -> None Thanks for the tip. This does indeed eliminate the errors with a non-blocking channel. But I still get excessive CPU usage. I have also tried setting the priority on add_watch (both `DEFAULT_IDLE and `LOW). Nothing seems to make any difference. It's true that my app does allow other programs to grab a significant amount of CPU time when they need it. But when my app is idle and not much else is running, 'top' shows it using over 90% of the CPU. That's certainly not normal, and I would think very undesirable. A 'sleep' call might help, but the standard Unix.sleep only accepts 1-second increments, which is undesirable. But I can try a wrapper for usleep() ... unless someone has a better idea. -- Matt Gushee : Bantam - lightweight file manager : matt.gushee.net/software/bantam/ : : RASCL's A Simple Configuration Language : matt.gushee.net/rascl/ :