Re: Problem with MacPerl
by Trimbach (Curate) on Feb 14, 2001 at 23:19 UTC
|
Instead of "sleeping" your program you should look into one of the cron-type programs available for Macintosh. One of them is the commercial
MacAT another is the shareware
Chronograph Or, since your problem is so well defined, you might be able to just whip up some Applescript that'll do it for you.
Of course, when OS X comes out next month, you'll have access to real cron and preemptive multitasking and this won't be a problem at all. :-D
Gary Blackburn
Trained Killer | [reply] |
Re: Problem with MacPerl
by CiceroLove (Monk) on Feb 15, 2001 at 00:20 UTC
|
I'm come from a long line of Mac lovers. (I'm looking at my PowerBook G3 running my mail server right now). MacPerl is in my opinion a dastardly half-migration of Perl per se. Things like sleep and @readinlines = <DATAFILE>; do not work as expected if you are coming from a *NIX environment. I am sad to say that sleep is just as dastardly in AppleScript. (as a side note, sleep is also a crappy command in AppleScript but is supposed to be changed in OSX). The reason why sleep does not work is that it cannot break the "command cycle". That si to say it must wait until an empty moment to be run. But it's sleeping so the OS just skips right over its request, the script wakes up because the OS "touched" it and then waits until the OS comes around again. But by that time it's already asleep again! This is obviously not the intended behaviour. An Apple Engineer explained to me at MacWorld that the best thing to do is give it a task that must be waited upon by the OS, so that the suggestion above to do selects and stuff is probably your best short term bet. In that way, you can be doing something in the background that would require the OS to leave and come back to give processor time you would have a better chance of getting your script to run. Or using an extension (I can't remember the name of some right now but you can find them on versiontracker.com) because extensions live in the processor cycle. I know htis is long but one last thing. There is a Scripting Addition that does true mutli-tasking that you could use with Appelscript to create a similar "sleep" behaviour. You can email me at gregs@l90.com is you want more info.
HTH
CiceroLove | [reply] [d/l] |
|
Just to add to the previous node, you can use Scripting Additions directly from MacPerl using the Mac::Glue module if you want to go that route.
----
Coyote
| [reply] |
|
@array = <FILE> works exactly the same as on Unix. It is just entirely false to say otherwise.
And sleep() works as intended. OK, so it can't just begin sleeping right away if something else is happening; welcome to cooperative multitasking! To blame MacPerl for the Mac OS architecture is pretty silly.
One may also wish to look into Mac::Events::WaitNextEvent() for some purposes.
| [reply] |
(Coyote) Re: Problem with MacPerl
by Coyote (Deacon) on Feb 15, 2001 at 00:14 UTC
|
You can get around the multitasking problem on the Mac by running multiple instances of the interpreter by creating runtime versions of your scripts. You can do this from the MacPerl save dialog. I have had success with this approach in the past with some long running data crunching scripts. If I understand the process correctly, creating a runtime version makes a copy of the MacPerl executable and adds your script and required modules to the resource fork of the MacPerl copy, so this can eat up quite a bit of diskspace. I would recommend creating a runtime version of your script and using one of the schedulers that Trimbach mentioned in an earlier node.
Hope this helps.
----
Coyote | [reply] |
Re: Problem with MacPerl
by kschwab (Vicar) on Feb 14, 2001 at 20:45 UTC
|
I know nothing about Macs, but perhaps
replacing sleep() calls with something like:
sub mysleep {
select(undef,undef,undef,$_[0]);
}
would change the underlying call to something
friendlier to the cooperative multitasking ? | [reply] [d/l] |
Re: Problem with MacPerl
by raster (Novice) on Feb 15, 2001 at 03:20 UTC
|
I'd do one of two things, use a scheduler (I like T-Minus Ten, but there are other cron-like apps for the Mac) or if that's no good, you can have an AppleScript that remains open, sleeping most of the time, and running the script every x amount of minutes. You might try the MacPerl list or archives for more specifics, or helpful individuals - http://www.macperl.org/
| [reply] |
Re: Problem with MacPerl
by gambler (Initiate) on Feb 15, 2001 at 05:21 UTC
|
Just wanted to thank all those that replied! I think I will try out a couple of the schedulers mentioned tommorow-I'll let you know how it goes.
Thanks again,gambler | [reply] |