From nkuipers at uvic.ca Mon Feb 3 14:58:04 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:15 2004 Subject: cool Message-ID: <3E3EF5FC@wm2.uvic.ca> I played around in recursion a bit, wanting to get the practice but also to do something useful. So I framed it to myself as an exercise. This was my first idea: #!/usr/bin/perl use strict; use warnings; =pod write a recursive function that generates a random DNA sequence of length N =cut sub makeDNA { my $n = shift; my @alphabet = qw( A C G T); if ($lengthRemaining == 0) { return; } print $alphabet[int(rand(4))]; makeDNA($n - 1); } makeDNA(10); print "\n"; This could develop into a small host of other recursive, random functionalities useful for bioinformatics, such as taking a sequence and randomly mutating n residues. I will be incorporating above subroutine and possibly others in my BIO::Basic module. Cheers, Nathanael Kuipers From nkuipers at uvic.ca Mon Feb 3 14:59:57 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:15 2004 Subject: hehe Message-ID: <3E3EF75C@wm2.uvic.ca> I changed $lengthRemaining to $n after successfully testing the script, to better fit the pod statement, and forgot to update the if statement: sub makeDNA { my $n = shift; my @alphabet = qw( A C G T); if ($n == 0) { return; } print $alphabet[int(rand(4))]; makeDNA($n - 1); } From Peter at PSDT.com Mon Feb 3 15:28:38 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:15 2004 Subject: cool In-Reply-To: <3E3EF5FC@wm2.uvic.ca> Message-ID: <4.3.2.7.2.20030203130509.00b2feb0@shell2.webquarry.com> At 12:58 PM 2/3/03 -0800, nkuipers wrote: >I played around in recursion a bit, wanting to get the practice but >also to do >something useful. So I framed it to myself as an exercise. This was >my first >idea: >[snip] >sub makeDNA { > my $n = shift; > my @alphabet = qw( A C G T); > if ($lengthRemaining == 0) > { > return; > } > print $alphabet[int(rand(4))]; > makeDNA($n - 1); >} > >makeDNA(10); >print "\n"; > >This could develop into a small host of other recursive, random >functionalities useful for bioinformatics, such as taking a sequence and >randomly mutating n residues. I will be incorporating above subroutine and >possibly others in my BIO::Basic module. Well, hold on a second... fun as recursion may be, it is not a panacea. It is only optimal in the cases where you really do find yourself wanting to call the same function from within itself. I suggest familiarizing yourself with a number of classic uses of recursion before deciding to use it. Look for: The Tower of Hanoi, Ackerman's function, and anything to do with parsing a stream which may be lexically recursive in some fashion. I'd write yon function above as sub makeDNA { join '' => map +(qw(A C G T))[rand 4] => 1 .. shift; } In general, don't print from inside utility functions. Return strings instead so you can either print them or decide to do something else with them (e.g., run them through tests). -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From nkuipers at uvic.ca Mon Feb 3 17:10:10 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:15 2004 Subject: cool Message-ID: <3E3F17E0@wm2.uvic.ca> Yes you are right, this case is just as effectively solved non-recursively and the reminder not to get carried away is well received. If I were to chide your solution however, I might say that it is very difficult to read to anyone not familiar with a breadth of perl idioms, everything from shift and qw() which I also used, to preceding parens with + for making something not look like a function call (if I remember correctly), => comma equivalence, and some rather heavy operator chaining. ;) nathanael >===== Original Message From Peter Scott ===== >At 12:58 PM 2/3/03 -0800, nkuipers wrote: >>I played around in recursion a bit, wanting to get the practice but >>also to do >>something useful. So I framed it to myself as an exercise. This was >>my first >>idea: >>[snip] >>sub makeDNA { >> my $n = shift; >> my @alphabet = qw( A C G T); >> if ($lengthRemaining == 0) >> { >> return; >> } >> print $alphabet[int(rand(4))]; >> makeDNA($n - 1); >>} >> >>makeDNA(10); >>print "\n"; >> >>This could develop into a small host of other recursive, random >>functionalities useful for bioinformatics, such as taking a sequence and >>randomly mutating n residues. I will be incorporating above subroutine and >>possibly others in my BIO::Basic module. > >Well, hold on a second... fun as recursion may be, it is not a >panacea. It is only optimal in the cases where you really do find >yourself wanting to call the same function from within itself. I >suggest familiarizing yourself with a number of classic uses of >recursion before deciding to use it. Look for: The Tower of Hanoi, >Ackerman's function, and anything to do with parsing a stream which may >be lexically recursive in some fashion. > >I'd write yon function above as > >sub makeDNA >{ > join '' => map +(qw(A C G T))[rand 4] => 1 .. shift; >} > >In general, don't print from inside utility functions. Return strings >instead so you can either print them or decide to do something else >with them (e.g., run them through tests). > >-- >Peter Scott >Pacific Systems Design Technologies >http://www.perldebugged.com/ From Peter at PSDT.com Mon Feb 3 17:16:17 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:15 2004 Subject: cool In-Reply-To: <3E3F17E0@wm2.uvic.ca> Message-ID: <4.3.2.7.2.20030203151303.00b26100@shell2.webquarry.com> At 03:10 PM 2/3/03 -0800, nkuipers wrote: >Yes you are right, this case is just as effectively solved >non-recursively and >the reminder not to get carried away is well received. If I were to chide >your solution however, I might say that it is very difficult to read >to anyone >not familiar with a breadth of perl idioms, everything from shift and qw() >which I also used, to preceding parens with + for making something not look >like a function call (if I remember correctly), => comma equivalence, >and some >rather heavy operator chaining. > >;) See, it's not just a function but a tutorial! :-) Okay, perhaps you'd prefer: sub makeDNA { my $count = shift; my @bits = qw(A C G T); my $res; for (1 .. $count) { $res .= $bits[rand @bits]; } return $res; } >nathanael > > > >===== Original Message From Peter Scott ===== > >At 12:58 PM 2/3/03 -0800, nkuipers wrote: > >>I played around in recursion a bit, wanting to get the practice but > >>also to do > >>something useful. So I framed it to myself as an exercise. This was > >>my first > >>idea: > >>[snip] > >>sub makeDNA { > >> my $n = shift; > >> my @alphabet = qw( A C G T); > >> if ($lengthRemaining == 0) > >> { > >> return; > >> } > >> print $alphabet[int(rand(4))]; > >> makeDNA($n - 1); > >>} > >> > >>makeDNA(10); > >>print "\n"; > >> > >>This could develop into a small host of other recursive, random > >>functionalities useful for bioinformatics, such as taking a sequence and > >>randomly mutating n residues. I will be incorporating above subroutine and > >>possibly others in my BIO::Basic module. > > > >Well, hold on a second... fun as recursion may be, it is not a > >panacea. It is only optimal in the cases where you really do find > >yourself wanting to call the same function from within itself. I > >suggest familiarizing yourself with a number of classic uses of > >recursion before deciding to use it. Look for: The Tower of Hanoi, > >Ackerman's function, and anything to do with parsing a stream which may > >be lexically recursive in some fashion. > > > >I'd write yon function above as > > > >sub makeDNA > >{ > > join '' => map +(qw(A C G T))[rand 4] => 1 .. shift; > >} > > > >In general, don't print from inside utility functions. Return strings > >instead so you can either print them or decide to do something else > >with them (e.g., run them through tests). > > > >-- > >Peter Scott > >Pacific Systems Design Technologies > >http://www.perldebugged.com/ -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From peter at PSDT.com Mon Feb 3 19:03:58 2003 From: peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:15 2004 Subject: Stupid mistakes, vol 1 Message-ID: <4.3.2.7.2.20030203170201.00b30d50@shell2.webquarry.com> Don't do use base qw(Exporter); our @EXPORT = qw(some_func); sub some_func { } and then spend ages scratching your head as to why some_func is not exported to the caller only to discover that elsewhere in the same module you had earlier inserted your own import(). Doh! -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From darren at DarrenDuncan.net Mon Feb 3 22:27:37 2003 From: darren at DarrenDuncan.net (Darren Duncan) Date: Wed Aug 4 00:11:15 2004 Subject: Stupid mistakes, vol 1 Message-ID: Peter Scott said: >Don't do > > use base qw(Exporter); > our @EXPORT = qw(some_func); > > sub some_func { } > >and then spend ages scratching your head as to why some_func is not exported to the caller only to discover that elsewhere in the same module you had earlier inserted your own import(). Of course, I could also say, don't import/export at all, but use objects for everything. This way, you save having to mess with your caller's namespace. While there are some niceties that you lose when going all objects, I think it is a small price to pay for what you gain; and you haven't actually *lost* anything, except a few seconds typing more characters when coding, and a bit steeper of an initial learning curve. -- Darren Duncan From abez at abez.ca Fri Feb 7 16:27:52 2003 From: abez at abez.ca (abez) Date: Wed Aug 4 00:11:15 2004 Subject: TPJ Message-ID: New issue of TPJ is out. I'm not too happy with it. Somewhat lacking stuff that really interests me other than the code for "super". Does anyone know about Aspect Oriented Programming under Perl? As well when should we meet? Darren was saying he was available in the last week of Febuary. Does anyone want to put on a lecture? abram -- abez ------------------------------------------ http://www.abez.ca/ Abram Hindle (abez@abez.ca) ------------------------------------------ abez From Peter at PSDT.com Fri Feb 7 16:43:42 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:15 2004 Subject: TPJ In-Reply-To: Message-ID: <4.3.2.7.2.20030207144215.00ab39a0@shell2.webquarry.com> At 02:27 PM 2/7/03 -0800, abez wrote: >New issue of TPJ is out. I'm not too happy with it. Somewhat lacking stuff >that really interests me other than the code for "super". > >Does anyone know about Aspect Oriented Programming under Perl? http://search.cpan.org/author/MARCEL/Aspect-0.08/lib/Aspect/Overview.pod >As well when should we meet? Darren was saying he was available in the last >week of Febuary. I'm open. >Does anyone want to put on a lecture? How about Bioinformatics? hint, hint. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From nkuipers at uvic.ca Fri Feb 7 20:08:55 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:15 2004 Subject: TPJ Message-ID: <3E446734@wm2.uvic.ca> >How about Bioinformatics? hint, hint. If I had gone to biocon this year, I'd be all over that, straining at the bit to relate my experiences. As it is, that is actually a difficult topic. It would have to include a crash course in some molecular biology, and a review of some of the applications in bioinformatics as a field. The obvious choice for a keynote topic is to highlight some components of the bioperl project, similar to Abram's presentation of WWW::Mechanize, which just issued its 1.2 release. I could also dig up some reviews of biocon(s) and present the main points, and then finish off with a quick review of the work I do (am trying to do). I'm not sure how interesting all that would be for you guys though... Nathanael From abez at abez.ca Fri Feb 7 20:11:30 2003 From: abez at abez.ca (abez) Date: Wed Aug 4 00:11:15 2004 Subject: TPJ In-Reply-To: <3E446734@wm2.uvic.ca> References: <3E446734@wm2.uvic.ca> Message-ID: I would enjoy a presentation on the subject irregardless. Crash course so be it, it sound interesting. abram On Fri, 7 Feb 2003, nkuipers wrote: > >How about Bioinformatics? hint, hint. > > If I had gone to biocon this year, I'd be all over that, straining at the bit > to relate my experiences. As it is, that is actually a difficult topic. It > would have to include a crash course in some molecular biology, and a review > of some of the applications in bioinformatics as a field. The obvious choice > for a keynote topic is to highlight some components of the bioperl project, > similar to Abram's presentation of WWW::Mechanize, which just issued its 1.2 > release. I could also dig up some reviews of biocon(s) and present the main > points, and then finish off with a quick review of the work I do (am trying to > do). I'm not sure how interesting all that would be for you guys though... > > Nathanael > -- abez ------------------------------------------ http://www.abez.ca/ Abram Hindle (abez@abez.ca) ------------------------------------------ abez From darren at DarrenDuncan.net Mon Feb 10 11:19:13 2003 From: darren at DarrenDuncan.net (Darren Duncan) Date: Wed Aug 4 00:11:15 2004 Subject: putting POD files on CPAN Message-ID: Hello. I have a quick question, and thought someone here could provide a quick answer. I will also ask this to several appropriate CPAN emails, but they may take longer. Specifically, I uploaded Rosetta-0.03 yesterday. The most significant change from 0.02 was splitting the documentation off into a separate file, "Documentation.pod"; this file is currently in the distribution root folder (note that I put Rosetta.pm in lib/ and Rosetta.t in t/). Unfortunately, the CPAN search site at "http://search.cpan.org/dist/Rosetta/" did not convert the file to HTML and list it at the above url. I have to go to the src/ directory to see it, and the file is unformatted there. I would like the interpreted POD to appear in the main distribution details page like the POD extracted from Rosetta.pm does. What do I need to change in my distribution for this to happen? (I would like to upload a fix to this ASAP.) Thank you in advance for any help. -- Darren Duncan From peter at PSDT.com Mon Feb 10 11:25:42 2003 From: peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:15 2004 Subject: putting POD files on CPAN In-Reply-To: Message-ID: <4.3.2.7.2.20030210092347.00b5a760@shell2.webquarry.com> At 09:19 AM 2/10/03 -0800, Darren Duncan wrote: >Hello. I have a quick question, and thought someone here could provide a >quick answer. I will also ask this to several appropriate CPAN emails, >but they may take longer. > >Specifically, I uploaded Rosetta-0.03 yesterday. The most significant >change from 0.02 was splitting the documentation off into a separate file, >"Documentation.pod"; this file is currently in the distribution root >folder (note that I put Rosetta.pm in lib/ and Rosetta.t in t/). > >Unfortunately, the CPAN search site at >"http://search.cpan.org/dist/Rosetta/" did not convert the file to HTML >and list it at the above url. I have to go to the src/ directory to see >it, and the file is unformatted there. I would like the interpreted POD >to appear in the main distribution details page like the POD extracted >from Rosetta.pm does. > >What do I need to change in my distribution for this to happen? (I would >like to upload a fix to this ASAP.) Might need to ask the CPAN folks about that. Documentation.pod doesn't sound very standard practice to me. Perhaps it needs to be in lib/ instead of the root. Or a pod/ directory, following the Perl core pattern. If you're going to make a separate .pod file wouldn't Rosetta.pod be a better name? -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From darren at DarrenDuncan.net Mon Feb 10 11:47:22 2003 From: darren at DarrenDuncan.net (Darren Duncan) Date: Wed Aug 4 00:11:15 2004 Subject: putting POD files on CPAN In-Reply-To: <4.3.2.7.2.20030210092347.00b5a760@shell2.webquarry.com> Message-ID: On Mon, 10 Feb 2003, Peter Scott wrote: > Might need to ask the CPAN folks about that. Documentation.pod doesn't > sound very standard practice to me. Perhaps it needs to be in lib/ > instead of the root. Or a pod/ directory, following the Perl core > pattern. If you're going to make a separate .pod file wouldn't > Rosetta.pod be a better name? Thanks for the reply. I also sent a modified version of the email to modules@perl.org and the feedback page on search.cpan.org. While it seems less common (hence my difficulty in finding examples), I had the impression that lots of people had standalone POD files in their distributions, for times when they had documentation that was not specific to a single module. I was trying to do the same, but since I hadn't done it before, this upload was sort of an experiment. I expect it would be possible and I just have to tweak something, but I needed to know what due to the difficulty in re-finding examples. If I do have to re-upload, I'll take your suggestion and rename the file to Rosetta.pod or something like that. Have a good day. -- Darren Duncan From darren at DarrenDuncan.net Mon Feb 10 13:51:16 2003 From: darren at DarrenDuncan.net (Darren Duncan) Date: Wed Aug 4 00:11:15 2004 Subject: putting POD files on CPAN In-Reply-To: <4.3.2.7.2.20030210092347.00b5a760@shell2.webquarry.com> Message-ID: On Mon, 10 Feb 2003, Peter Scott wrote: > Might need to ask the CPAN folks about that. Documentation.pod doesn't > sound very standard practice to me. Perhaps it needs to be in lib/ > instead of the root. Or a pod/ directory, following the Perl core > pattern. If you're going to make a separate .pod file wouldn't > Rosetta.pod be a better name? As a follow-up, I have gotten a reply from Graham Barr, who was the recipient of the Feedback page on CPAN Search. His first reply said that my Rosetta.pm and Documentation.pod both had the same Name, which caused only one to be indexed, and he asked why I was doing what I was doing, which looked non-standard. After I replied to that, he gave me an answer like what I was looking for. For your reference, a copy of it is below. It looked like your own suggestion, Peter, about filing under lib/. Have a good day. -- Darren Duncan --------------------------------------------- From: Graham Barr I would suggest putting it in a file under lib/Rosetta, say for example lib/Rosetta/Framework.pod but make sutr that the line in the NAME section starts with Rosetta::Framework so the search site knows this is not the pod for the Rosetta module. You find other distributions do this for thier faq (eg Rosetta::FAQ in lib/Rosetta/FAQ.pod) Graham. From abez at abez.ca Mon Feb 10 16:23:59 2003 From: abez at abez.ca (abez) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? Message-ID: We should meet sometime on the 24,25,26 or 27 of febuary. 24 being a monday. My preference is for the 25th. We should decide soon so I can reserve a room. abram -- abez ------------------------------------------ http://www.abez.ca/ Abram Hindle (abez@abez.ca) ------------------------------------------ abez From nkuipers at uvic.ca Mon Feb 10 16:35:12 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? Message-ID: <3E4840C1@wm2.uvic.ca> I would prefer Monday the 24th. >===== Original Message From abez ===== >We should meet sometime on the 24,25,26 or 27 of febuary. 24 being a monday. >My preference is for the 25th. > >We should decide soon so I can reserve a room. > >abram > >-- >abez ------------------------------------------ >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >------------------------------------------ abez From Peter at PSDT.com Mon Feb 10 16:37:13 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? In-Reply-To: <3E4840C1@wm2.uvic.ca> Message-ID: <4.3.2.7.2.20030210143657.00b578f0@shell2.webquarry.com> At 02:35 PM 2/10/03 -0800, nkuipers wrote: >I would prefer Monday the 24th. That works for me too... all choices are fine. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From Peter at PSDT.com Mon Feb 10 16:36:35 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? In-Reply-To: Message-ID: <4.3.2.7.2.20030210143551.00b683f0@shell2.webquarry.com> At 02:23 PM 2/10/03 -0800, abez wrote: >We should meet sometime on the 24,25,26 or 27 of febuary. 24 being a monday. >My preference is for the 25th. Works for me. Any other opinions? >We should decide soon so I can reserve a room. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From darren at DarrenDuncan.net Mon Feb 10 17:21:44 2003 From: darren at DarrenDuncan.net (Darren Duncan) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? In-Reply-To: Message-ID: On Mon, 10 Feb 2003, abez wrote: > We should meet sometime on the 24,25,26 or 27 of febuary. 24 being a monday. > My preference is for the 25th. > We should decide soon so I can reserve a room. > abram I would say that the Tuesday is preferable for me also; if not that day, then the Thursday. Wednesday would likely be a conflict. Monday is better than Wednesday, but not desirable because it is the day after I return from my long flight, so may be too tired to stay in. But how does things work out for others? -- Darren Duncan From abez at abez.ca Mon Feb 10 19:49:10 2003 From: abez at abez.ca (abez) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? In-Reply-To: References: Message-ID: So which day Tuesday or Monday boys? abram On Mon, 10 Feb 2003, Darren Duncan wrote: > On Mon, 10 Feb 2003, abez wrote: > > We should meet sometime on the 24,25,26 or 27 of febuary. 24 being a monday. > > My preference is for the 25th. > > We should decide soon so I can reserve a room. > > abram > > I would say that the Tuesday is preferable for me also; if not that day, > then the Thursday. Wednesday would likely be a conflict. Monday is > better than Wednesday, but not desirable because it is the day after I > return from my long flight, so may be too tired to stay in. But how does > things work out for others? -- Darren Duncan > -- abez ------------------------------------------ http://www.abez.ca/ Abram Hindle (abez@abez.ca) ------------------------------------------ abez From Peter at PSDT.com Mon Feb 10 19:49:31 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? In-Reply-To: References: Message-ID: <4.3.2.7.2.20030210174923.00b01f00@shell2.webquarry.com> At 05:49 PM 2/10/03 -0800, abez wrote: >So which day Tuesday or Monday boys? Prefer Monday. >abram > >On Mon, 10 Feb 2003, Darren Duncan wrote: > > > On Mon, 10 Feb 2003, abez wrote: > > > We should meet sometime on the 24,25,26 or 27 of febuary. 24 > being a monday. > > > My preference is for the 25th. > > > We should decide soon so I can reserve a room. > > > abram > > > > I would say that the Tuesday is preferable for me also; if not that day, > > then the Thursday. Wednesday would likely be a conflict. Monday is > > better than Wednesday, but not desirable because it is the day after I > > return from my long flight, so may be too tired to stay in. But how does > > things work out for others? -- Darren Duncan > > > >-- >abez ------------------------------------------ >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >------------------------------------------ abez -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From darren at DarrenDuncan.net Mon Feb 10 21:01:18 2003 From: darren at DarrenDuncan.net (Darren Duncan) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? In-Reply-To: References: Message-ID: At 5:49 PM -0800 2/10/03, abez wrote: >So which day Tuesday or Monday boys? > >abram Tuesday is still best for me regarding getting a ride home (unless there are things going on that I don't know about). That said, if the rest of you want to go on Monday then I would sooner try to make that day work for myself than make one of you miss it or not go at all. -- Darren Duncan From abez at abez.ca Mon Feb 10 21:05:48 2003 From: abez at abez.ca (abez) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? In-Reply-To: References: Message-ID: Well we have 2 votes for monday and one undecided and one Tuesday. I think we should go for monday then as there is a clear preference. abram On Mon, 10 Feb 2003, Darren Duncan wrote: > At 5:49 PM -0800 2/10/03, abez wrote: > >So which day Tuesday or Monday boys? > > > >abram > > Tuesday is still best for me regarding getting a ride home (unless there are things going on that I don't know about). That said, if the rest of you want to go on Monday then I would sooner try to make that day work for myself than make one of you miss it or not go at all. -- Darren Duncan > -- abez ------------------------------------------ http://www.abez.ca/ Abram Hindle (abez@abez.ca) ------------------------------------------ abez From nkuipers at uvic.ca Mon Feb 10 21:13:47 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? Message-ID: <3E486CCC@wm2.uvic.ca> tipScales(Monday); >===== Original Message From abez ===== >Well we have 2 votes for monday and one undecided and one Tuesday. > >I think we should go for monday then as there is a clear preference. > >abram > >On Mon, 10 Feb 2003, Darren Duncan wrote: > >> At 5:49 PM -0800 2/10/03, abez wrote: >> >So which day Tuesday or Monday boys? >> > >> >abram >> >> Tuesday is still best for me regarding getting a ride home (unless there are things going on that I don't know about). That said, if the rest of you want to go on Monday then I would sooner try to make that day work for myself than make one of you miss it or not go at all. -- Darren Duncan >> > >-- >abez ------------------------------------------ >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >------------------------------------------ abez From Peter at PSDT.com Tue Feb 11 11:24:02 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? In-Reply-To: References: Message-ID: <4.3.2.7.2.20030211092335.00a9dcd0@shell2.webquarry.com> At 07:05 PM 2/10/03 -0800, abez wrote: >Well we have 2 votes for monday and one undecided and one Tuesday. > >I think we should go for monday then as there is a clear preference. Okay, Monday the 24th it is. Abram, you'll reserve a room? -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From darren at DarrenDuncan.net Tue Feb 11 12:15:27 2003 From: darren at DarrenDuncan.net (Darren Duncan) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? In-Reply-To: <4.3.2.7.2.20030211092335.00a9dcd0@shell2.webquarry.com> Message-ID: On Tue, 11 Feb 2003, Peter Scott wrote: > Okay, Monday the 24th it is. Abram, you'll reserve a room? Peter, based on a talk I had last night about VLUG with Andrew Willard, I found that you used to post notices of victoria-pm meetings on their list, but then stopped several months ago. It sounds like the group found those monthly notices useful. Are you still active in VLUG? I suggest that perhaps renewed meeting notices may bring in a few more people. If not you, then I think that victoria-pm has other members who are in both groups. (On a side note, I'm planning to attend my first VLUG meeting tonight. My preconception was that the general discussions were over my head, but I thought I would see in practice.) -- Darren Duncan From darren at DarrenDuncan.net Tue Feb 11 12:19:20 2003 From: darren at DarrenDuncan.net (Darren Duncan) Date: Wed Aug 4 00:11:15 2004 Subject: putting POD files on CPAN In-Reply-To: <4.3.2.7.2.20030210092347.00b5a760@shell2.webquarry.com> Message-ID: As a final follow-up to this thread, I uploaded Rosetta-0.04 last night, and this morning I found the CPAN Search site now displays all the files correctly, including the POD-only files. So the problem is solved. Thanks again and good day. -- Darren Duncan From Peter at PSDT.com Tue Feb 11 12:34:11 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? In-Reply-To: References: <4.3.2.7.2.20030211092335.00a9dcd0@shell2.webquarry.com> Message-ID: <4.3.2.7.2.20030211102851.00b6c100@shell2.webquarry.com> At 10:15 AM 2/11/03 -0800, Darren Duncan wrote: >On Tue, 11 Feb 2003, Peter Scott wrote: > > Okay, Monday the 24th it is. Abram, you'll reserve a room? > >Peter, based on a talk I had last night about VLUG with Andrew Willard, I >found that you used to post notices of victoria-pm meetings on their list, >but then stopped several months ago. It sounds like the group found those >monthly notices useful. Are you still active in VLUG? I suggest that >perhaps renewed meeting notices may bring in a few more people. If not >you, then I think that victoria-pm has other members who are in both >groups. (On a side note, I'm planning to attend my first VLUG meeting >tonight. My preconception was that the general discussions were over my >head, but I thought I would see in practice.) -- Darren Duncan Darren, you bring up a good point. I stopped posting notices to VLUG because I had already spammed - er, advertised - there twice, and I thought it impolite to continue sending such notices there without some indication that the cross-fertilization was approved. I won't be going tonight, but perhaps you can ask the higher-ups there what they think about your suggestion. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From darren at DarrenDuncan.net Tue Feb 11 12:56:10 2003 From: darren at DarrenDuncan.net (Darren Duncan) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? In-Reply-To: <4.3.2.7.2.20030211102851.00b6c100@shell2.webquarry.com> Message-ID: On Tue, 11 Feb 2003, Peter Scott wrote: > Darren, you bring up a good point. I stopped posting notices to VLUG > because I had already spammed - er, advertised - there twice, and I > thought it impolite to continue sending such notices there without some > indication that the cross-fertilization was approved. > > I won't be going tonight, but perhaps you can ask the higher-ups there > what they think about your suggestion. OK, I will ask them, assuming I remember. -- Darren Duncan From abez at abez.ca Tue Feb 11 17:26:07 2003 From: abez at abez.ca (abez) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? In-Reply-To: <4.3.2.7.2.20030211092335.00a9dcd0@shell2.webquarry.com> References: <4.3.2.7.2.20030211092335.00a9dcd0@shell2.webquarry.com> Message-ID: Clearihue A206, same room as last time. We'll also have projector access if anyone brings a laptop. If not transparencies usually work or just plain chalk. Nathan I assume you're going to give us a presentation on your bio/perl experience. If you could send me a name of your talk I'll make some posters to place around campus. abram On Tue, 11 Feb 2003, Peter Scott wrote: > At 07:05 PM 2/10/03 -0800, abez wrote: > >Well we have 2 votes for monday and one undecided and one Tuesday. > > > >I think we should go for monday then as there is a clear preference. > > Okay, Monday the 24th it is. Abram, you'll reserve a room? > > -- > Peter Scott > Pacific Systems Design Technologies > http://www.perldebugged.com/ > -- abez ------------------------------------------ http://www.abez.ca/ Abram Hindle (abez@abez.ca) ------------------------------------------ abez From nkuipers at uvic.ca Tue Feb 11 18:43:00 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? Message-ID: <3E49A194@wm2.uvic.ca> >Nathan I assume you're going to give us a presentation on your bio/perl >experience. If you could send me a name of your talk I'll make some posters to >place around campus. Yep I've been working on it, about to do the final section of it now. Title at the moment is: Lord of the Strings: Perl in biological applications Nathanael Kuipers Center for Biomedical Research Dept. of Biology, University of Victoria Thanks Abram, Nathanael From Peter at PSDT.com Tue Feb 11 21:22:24 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:15 2004 Subject: Decide on Meeting Date? In-Reply-To: <3E49A194@wm2.uvic.ca> Message-ID: <4.3.2.7.2.20030211192058.00b761e0@shell2.webquarry.com> At 04:43 PM 2/11/03 -0800, nkuipers wrote: > >Nathan I assume you're going to give us a presentation on your bio/perl > >experience. If you could send me a name of your talk I'll make some posters >to > >place around campus. > >Yep I've been working on it, about to do the final section of it now. Title >at the moment is: > >Lord of the Strings: Perl in biological applications Damn, that is a killer title. If you originated it, my hat is off to you. On another note, if anyone knows who bcase@telus.net is, tell them by whatever means you can that their mailbox is full and every message sent to the Victoria.pm list causes a bounce to *me* saying so. I am going to unsubscribe him/her shortly if it continues. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From peter at PSDT.com Thu Feb 13 13:23:48 2003 From: peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:15 2004 Subject: Victoria Perl Mongers Meeting Feb 24 Message-ID: <4.3.2.7.2.20030213111628.00b81370@shell2.webquarry.com> Victoria.pm will meet Monday Feb 24, 7pm, at UVic's Clearihue A206. Nathanael Kuipers will speak on: "Lord of the Strings: Perl in Biological Applications." For those unfamiliar with UVic, see grid C3. Parking can be found at the top centre of B3. If you don't know how to get to UVic - welcome to Victoria - see . Other topics to be covered as time permits; make requests for anything particular. (Courtesy copy to VLUG members by permission of the list manager. Victoria.pm's home page is .) -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From nkuipers at uvic.ca Wed Feb 19 17:51:18 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:15 2004 Subject: inheritance Message-ID: <3E542EEE@wm2.uvic.ca> Hello, I've been playing around with inheritance and I've got a question. Let's say the parent class is called BIO::Basic and the child class is called BIO::Annotate, and each class is in a separate file. Parent constructor is as follows: sub new { my $caller = shift; my $type = ref($caller) || $caller; my $self = { id => 'no value', desc => 'no value', seq => 'no value', alphabet => 'no value', profile => {}, @_ }; . . . bless $self, $type; } Child constructor is as follows: sub new { my $type = shift; my $self = {}; $self->{bogus_key} = BIO::Basic->new(@_); bless $self, $type; } If I just call $self = BIO::Basic->new(@_), then Annotate objects cannot use Basic methods. Addition of the {super} key in Annotate's self allows access to Basic methods in the driver script, as in: $annotate_object->{bogus_key}->parent_method(); Am I missing something here? Isn't there a simpler way? I guess I'm used to the inheritance of java. I got the above approach from http://www.perldoc.com/perl5.6/pod/perlbot.html Thanks, Nathanael From Peter at PSDT.com Wed Feb 19 18:03:11 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:16 2004 Subject: inheritance In-Reply-To: <3E542EEE@wm2.uvic.ca> Message-ID: <4.3.2.7.2.20030219155549.00ab4100@shell2.webquarry.com> At 03:51 PM 2/19/03 -0800, nkuipers wrote: >Hello, > >I've been playing around with inheritance and I've got a question. Let's say >the parent class is called BIO::Basic and the child class is called >BIO::Annotate, and each class is in a separate file. > >Parent constructor is as follows: > >sub new { > my $caller = shift; > my $type = ref($caller) || $caller; > my $self = { id => 'no value', > desc => 'no value', > seq => 'no value', > alphabet => 'no value', > profile => {}, > @_ }; >. >. >. >bless $self, $type; >} > >Child constructor is as follows: > >sub new { > my $type = shift; > my $self = {}; > $self->{bogus_key} = BIO::Basic->new(@_); > bless $self, $type; >} > >If I just call $self = BIO::Basic->new(@_), then Annotate objects cannot use >Basic methods. Addition of the {super} key in Annotate's self allows access >to Basic methods in the driver script, as in: > >$annotate_object->{bogus_key}->parent_method(); > >Am I missing something here? Isn't there a simpler way? I guess I'm used to >the inheritance of java. I got the above approach from > >http://www.perldoc.com/perl5.6/pod/perlbot.html The problem with learning from a Baog O' Tricks page is that some fundamentals got glossed over. (Get Conway's book.) In this case you've missed the way that inheritance is done in Perl using @ISA. (In fact, perlbot ought to be updated to use "use base", which is better.) Inheritance is easier, much easier. Here's the child: package BIO::Annotate; use strict; use warnings; use base qw(BIO::Basic); sub new { my $caller = shift; my type = ref($caller) || $caller; my $self = $caller->SUPER::new(@_); # anything else you want to do with $self return $self; } SUPER is documented in perlobj. What you did is object "delegation". There is a raging controversy among O-O purists about when the best time to use this is. But it's not what you were looking for. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From nkuipers at uvic.ca Wed Feb 19 18:58:32 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:16 2004 Subject: inheritance Message-ID: <3E543DCE@wm2.uvic.ca> Well, typos aside, Peter's solution did not work for me; note that I had been using the base pragma all along. Then I realized that I had the following line as part of my module, since the skeleton was written way back when I was basically copying out of the Camel: @ISA = qw(Exporter); Hmmmmm didn't I feel like such a heel. I chose to nix all mention of Exporter, @EXPORT, @EXPORT_OK etc. And everything works as it should. Thanks Peter. Best, Nathanael From nkuipers at uvic.ca Thu Feb 20 12:46:16 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:16 2004 Subject: just a thought Message-ID: <3E553C64@wm2.uvic.ca> Yesterday I inadvertently illustrated use of "delegation" in Perl, in a roundabout way to establish inheritance in my BIO:: namespace. Peter, in addition to showing me the easy way to Perl inheritance, mentioned that there is a raging controversy among OO purists about when (if ever?) delegation should be used. I am thinking that this is a tremendously useful way to implement multiple inheritance. In the child class constructor, you could have a key for each parent name, where the value is the call to that parent's constructor. It would then be very easy to call any method from any parent, right from the child object: $object->{super1}->fooperdooper(); $object->{super2}->bazball(); You would also allow easy, hardcoded access to identically named methods in different parents: $object->{super1}->kindasorta(); $object->{super2}->kindasorta(); Am I more or less correct in my "realizations" about delegation? If so, I find it to be really quite exciting. Cheers all, Nathanael From Peter at PSDT.com Thu Feb 20 12:57:14 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:16 2004 Subject: just a thought In-Reply-To: <3E553C64@wm2.uvic.ca> Message-ID: <4.3.2.7.2.20030220105031.00bc47a0@shell2.webquarry.com> At 10:46 AM 2/20/03 -0800, nkuipers wrote: >Yesterday I inadvertently illustrated use of "delegation" in Perl, in a >roundabout way to establish inheritance in my BIO:: namespace. Peter, in >addition to showing me the easy way to Perl inheritance, mentioned that there >is a raging controversy among OO purists about when (if ever?) delegation >should be used. I am thinking that this is a tremendously useful way to >implement multiple inheritance. In the child class constructor, you could >have a key for each parent name, where the value is the call to that parent's >constructor. Well, they're not really parents; that term is reserved for inheritance. They're the delegates, or whatever they're called. >It would then be very easy to call any method from any parent, >right from the child object: > >$object->{super1}->fooperdooper(); >$object->{super2}->bazball(); > >You would also allow easy, hardcoded access to identically named methods in >different parents: > >$object->{super1}->kindasorta(); >$object->{super2}->kindasorta(); > >Am I more or less correct in my "realizations" about delegation? If >so, I find it to be really quite exciting. That's a neat model you have there. I'm not sure that it really qualifies as delegation since you are not going via the delegating object; I think delegation is when you call a method on an object and it delegates it to another object that it contains. So above you'd have to have $object->fooperdooper; $object->bazball; $object->kindasorta; and in the last case $object would have to decide which object to delegate it to. See . -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From abez at abez.ca Thu Feb 20 13:04:19 2003 From: abez at abez.ca (abez) Date: Wed Aug 4 00:11:16 2004 Subject: just a thought In-Reply-To: <3E553C64@wm2.uvic.ca> References: <3E553C64@wm2.uvic.ca> Message-ID: Checkout: http://cedar.csc.uvic.ca/twiki/kienle/pub/SENG430/CourseMaterial/IaS_handout.pdf Perl can already handle multiple inheritance so if you're using inheritance use that. Delegation is good for situations like say we have the structure Person | +--+----------+ | | Engineer Janitor We the problem here is that even if a Janitor gets training they can never be an engineer. Where as if Person delegates to a Job the system is much more flexible. Person---------------------->Job | +--+----------+ | | Engineer Janitor In languages like C++ or Java inheritance is usually faster than delegation. In a language like Perl I don't think it's much of an issue. In something like Java implementing a interface then delegating to an object made specifically to implement that interface would be similar to multiple inheritance yes. For instance PropertyChangeSupport provides event firing functionality to your class without the use of inheritance. On Thu, 20 Feb 2003, nkuipers wrote: > Yesterday I inadvertently illustrated use of "delegation" in Perl, in a > roundabout way to establish inheritance in my BIO:: namespace. Peter, in > addition to showing me the easy way to Perl inheritance, mentioned that there > is a raging controversy among OO purists about when (if ever?) delegation > should be used. I am thinking that this is a tremendously useful way to > implement multiple inheritance. In the child class constructor, you could > have a key for each parent name, where the value is the call to that parent's > constructor. It would then be very easy to call any method from any parent, > right from the child object: > > $object->{super1}->fooperdooper(); > $object->{super2}->bazball(); > > You would also allow easy, hardcoded access to identically named methods in > different parents: > > $object->{super1}->kindasorta(); > $object->{super2}->kindasorta(); > > Am I more or less correct in my "realizations" about delegation? If so, I > find it to be really quite exciting. > > Cheers all, > > Nathanael > -- abez ------------------------------------------ http://www.abez.ca/ Abram Hindle (abez@abez.ca) ------------------------------------------ abez From darren at DarrenDuncan.net Thu Feb 20 20:17:58 2003 From: darren at DarrenDuncan.net (Darren Duncan) Date: Wed Aug 4 00:11:16 2004 Subject: inheritance In-Reply-To: <3E542EEE@wm2.uvic.ca> Message-ID: On Wed, 19 Feb 2003, nkuipers wrote: > Child constructor is as follows: > > sub new { > my $type = shift; > my $self = {}; > $self->{bogus_key} = BIO::Basic->new(@_); > bless $self, $type; > } Your child constructor is incorrect, and in this case, unnecessary. Constructors are inherited, so when your child module starts with "use base 'Bio::Basic'", Perl see's all of that class' methods in Bio::Annotate without you doing anything else in the latter. This means that Perl would call the new() of Bio::Basic unless you declared a new() in the child. Since the parent class uses the value in $class in bless(), as any normal Perl class should (any class should be inheritable), it will already do the right thing, since $class would contain Bio::Annotate when you say "new Bio::Annotate", and the parent constructor will bless into Bio::Annotate. The only reason to make your own new() is if you need to override or supplement functionality in the parent's new(). In the latter case, your child class' new() should look like this: sub new { my $self = SUPER::new(@_); # puts blessed hash in $self # put other special functionality here return($self); } Note that "SUPER" is a special Perl keyword that refers to the parent class. That said (and I don't really like this), when you have multiple inheritence, SUPER won't work and you have to say instead "Bio::Basic::new(@_)". -- Darren Duncan From peter at PSDT.com Thu Feb 20 20:42:49 2003 From: peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:16 2004 Subject: inheritance In-Reply-To: References: <3E542EEE@wm2.uvic.ca> Message-ID: <4.3.2.7.2.20030220183858.00bc6c40@shell2.webquarry.com> At 06:17 PM 2/20/03 -0800, Darren Duncan wrote: >On Wed, 19 Feb 2003, nkuipers wrote: > > Child constructor is as follows: > > > > sub new { > > my $type = shift; > > my $self = {}; > > $self->{bogus_key} = BIO::Basic->new(@_); > > bless $self, $type; > > } > >Your child constructor is incorrect, and in this case, unnecessary. Correct, unless he wants to do something in the constructor before releasing the object into the wild. I should have said so before. >The only reason to make your own new() is if you need to >override or supplement functionality in the parent's new(). In the latter >case, your child class' new() should look like this: > >sub new { > my $self = SUPER::new(@_); # puts blessed hash in $self Hmm, and here all the time I've been doing my $class = shift; my $self = $class->SUPER::new(@_); Are you sure that with your approach it will go up the inheritance tree if it doesn't find new() in the first superclass? I thought you needed a -> method call for that. > # put other special functionality here > return($self); >} > >Note that "SUPER" is a special Perl keyword that refers to the parent >class. That said (and I don't really like this), when you have multiple >inheritence, SUPER won't work Well, it might :-) All depends which class it finds first. >and you have to say instead >"Bio::Basic::new(@_)". Assuming that's the parent you want to inherit the constructor. If you want some hybrid of the multiple parents' constructors you have to figure it out the hard way, right? -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From Peter at PSDT.com Fri Feb 21 14:03:09 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:16 2004 Subject: BC PM Message-ID: <4.3.2.7.2.20030221115243.00bc95b0@shell2.webquarry.com> My wife just had a cool idea; how about a summer time event where we get together with Vancouver.pm and Burnaby.pm? Joint meeting somewhere? CRoss-fertilization is wonderful. Location would be a question. Of course, we'd rather have them come here because it's nicer here and they'd have more fun in Victoria than we would on the mainland :-) If we met in the centroid that'd probably be Mayne Island. If we make it the weighted centroid it'd probably be in the Roberts Bank :-) Going further, we could work up to a Pacific NorthWest group meeting, everyone from Oregon to Alaska. I can float a BOF at OSCon to get together with whoever's there from those areas. Way to put Victoria on the Perl map! Comments? Anyone know anyone in the neighbouring PMs? -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From nkuipers at uvic.ca Fri Feb 21 15:45:26 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:16 2004 Subject: BC PM Message-ID: <3E569DF2@wm2.uvic.ca> I think that sounds like a fantastic idea, off the top of my head, sort of like dojos getting together for a friendly but hardworking practice. I'm not sure we could host it in Victoria because there are too few of us to billet any number of people (if billeting is the preferred way for our guests to go), although I admit it would be nice... >===== Original Message From Peter Scott ===== >My wife just had a cool idea; how about a summer time event where we >get together with Vancouver.pm and Burnaby.pm? Joint meeting >somewhere? CRoss-fertilization is wonderful. > >Location would be a question. Of course, we'd rather have them come >here because it's nicer here and they'd have more fun in Victoria than >we would on the mainland :-) If we met in the centroid that'd probably >be Mayne Island. If we make it the weighted centroid it'd probably be >in the Roberts Bank :-) > >Going further, we could work up to a Pacific NorthWest group meeting, >everyone from Oregon to Alaska. I can float a BOF at OSCon to get >together with whoever's there from those areas. Way to put Victoria on >the Perl map! > >Comments? Anyone know anyone in the neighbouring PMs? >-- >Peter Scott >Pacific Systems Design Technologies >http://www.perldebugged.com/ From darren at DarrenDuncan.net Fri Feb 21 20:59:40 2003 From: darren at DarrenDuncan.net (Darren Duncan) Date: Wed Aug 4 00:11:16 2004 Subject: inheritance In-Reply-To: <4.3.2.7.2.20030220183858.00bc6c40@shell2.webquarry.com> Message-ID: On Thu, 20 Feb 2003, Peter Scott wrote: > >sub new { > > my $self = SUPER::new(@_); # puts blessed hash in $self > > Hmm, and here all the time I've been doing > > my $class = shift; > my $self = $class->SUPER::new(@_); > > Are you sure that with your approach it will go up the inheritance tree > if it doesn't find new() in the first superclass? I thought you needed > a -> method call for that. You could be right. My previous email answer was strictly from memory. This time, I actually looked up some code I did before. The following is part of the source of CGI::Portable or its helper classes. A convention that I have always followed, which makes subclassing easier, is that my new() is totally generic, and I do the class-specific work in a separate initialize(); the latter is a normal method (except that it can't return anything), and is called by new(). Below are examples of new()/initialize() from 3 classes related through interitence. This is from CGI::Portable::Errors, which does not inherit anything, and it has properties: sub new { my $class = shift( @_ ); my $self = bless( {}, ref($class) || $class ); $self->initialize( @_ ); return( $self ); } sub initialize { my ($self) = @_; $self->{$KEY_ERRORS} = []; } This is from CGI::Portable::Files, which has single inheritence from CGI::Portable::Errors, and adds new properties: # sub new {} # We simply inherit this method and add no new functionality ourself. sub initialize { my ($self) = @_; $self->SUPER::initialize(); $self->{$KEY_FILE_PATH} = File::VirtualPath->new(); $self->{$KEY_PREFS} = {}; } This is from CGI::Portable, which has multiple inheritence from CGI::Portable::[Files,Request,Response], and adds new properties: sub new { my $class = shift( @_ ); my $self = bless( {}, ref($class) || $class ); $self->initialize( @_ ); return( $self ); } sub initialize { my ($self, $file_root, $file_delim, $prefs) = @_; $self->CGI::Portable::Files::initialize(); $self->CGI::Portable::Request::initialize(); $self->CGI::Portable::Response::initialize(); $self->{$KEY_IS_DEBUG} = undef; $self->{$KEY_PREF_APIT} = 'Untitled Application'; $self->{$KEY_PREF_MNAM} = 'Webmaster'; $self->{$KEY_PREF_MEAD} = 'webmaster@localhost'; $self->{$KEY_PREF_MESP} = undef; $self->{$KEY_PREF_SMTP} = 'localhost'; $self->{$KEY_PREF_TIME} = '30'; $self->{$KEY_MISC_OBJECTS} = {}; $self->file_path_root( $file_root ); $self->file_path_delimiter( $file_delim ); $self->set_prefs( $prefs ); } I suppose in retrospect that CGI::Portable didn't need to declare its own new(), since no matter which of its parent classes would have been called, any would have worked anyway. Perhaps I will remove this in an update. Hopefully those examples are helpful. It shows the range that I have actually seen working. -- Darren Duncan From Peter at PSDT.com Sat Feb 22 11:40:31 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:16 2004 Subject: Fwd: Perlish Quote Message-ID: <4.3.2.7.2.20030222093955.00bd4990@mail2a.jpl.nasa.gov> A friend just sent this to me. Great laugh. >http://philip.greenspun.com/panda/images.html > >ImageMagick is convenient but typing 300 commands like the above for >each PhotoCD would get tedious. You know that an MIT woman really >loves you when she offers to spare you the horrors of writing Perl. >Just grab http://photo.net/wtr/thebook/pcd-to-jpg-and-fpx.txt if you >want to use the Perl script that my girlfriend wrote as an expression >of her love for me. Of course, no romance is one sunny Perl-filled day >after another. When she delivered the code, I complained about the >lack of data abstraction and told her that she needed to reread >Structure and Interpretation of Computer Programs (Abelson and >Sussman; MIT Press 1997), the textbook for freshman computer science >at MIT. I also asked her to rename helper procedures that returned >Boolean values with "_p" ("predicate") suffixes. She replied "People >will laugh at you for being an old Lisp programmer clinging >pathetically to the 1960s" and then dumped me. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From Peter at PSDT.com Sat Feb 22 19:27:44 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:16 2004 Subject: inheritance In-Reply-To: References: <4.3.2.7.2.20030220183858.00bc6c40@shell2.webquarry.com> Message-ID: <4.3.2.7.2.20030222171621.00abb460@shell2.webquarry.com> At 06:59 PM 2/21/03 -0800, Darren Duncan wrote: >On Thu, 20 Feb 2003, Peter Scott wrote: > > >sub new { > > > my $self = SUPER::new(@_); # puts blessed hash in $self > > > > Hmm, and here all the time I've been doing > > > > my $class = shift; > > my $self = $class->SUPER::new(@_); > > > > Are you sure that with your approach it will go up the inheritance tree > > if it doesn't find new() in the first superclass? I thought you needed > > a -> method call for that. > >You could be right. I am: $ cat foo #!/usr/bin/perl -wl use strict; package Top; sub foo { print "Top: @_"; } package Middle; use base 'Top'; package Bottom; use base 'Middle'; sub foo { my $class = shift; $class->SUPER::foo(@_); } sub bar { SUPER::foo(@_); } package main; Bottom->foo(1,2,3); Bottom->bar(1,2,3); $ ./foo Top: Bottom 1 2 3 Undefined subroutine &SUPER::foo called at ./foo line 21. >My previous email answer was strictly from memory. >This time, I actually looked up some code I did before. The following is >part of the source of CGI::Portable or its helper classes. A convention >that I have always followed, which makes subclassing easier, is that my >new() is totally generic, and I do the class-specific work in a separate >initialize(); the latter is a normal method (except that it can't return >anything), and is called by new(). Below are examples of >new()/initialize() from 3 classes related through interitence. > >This is from CGI::Portable::Errors, which does not inherit anything, and >it has properties: > >sub new { > my $class = shift( @_ ); > my $self = bless( {}, ref($class) || $class ); > $self->initialize( @_ ); > return( $self ); >} > >sub initialize { > my ($self) = @_; > > $self->{$KEY_ERRORS} = []; >} I like this. >This is from CGI::Portable::Files, which has single inheritence from >CGI::Portable::Errors, and adds new properties: > ># sub new {} ># We simply inherit this method and add no new functionality ourself. > >sub initialize { > my ($self) = @_; > > $self->SUPER::initialize(); > > $self->{$KEY_FILE_PATH} = File::VirtualPath->new(); > $self->{$KEY_PREFS} = {}; >} > >This is from CGI::Portable, which has multiple inheritence from >CGI::Portable::[Files,Request,Response], and adds new properties: > >sub new { > my $class = shift( @_ ); > my $self = bless( {}, ref($class) || $class ); > $self->initialize( @_ ); > return( $self ); >} > >sub initialize { > my ($self, $file_root, $file_delim, $prefs) = @_; > > $self->CGI::Portable::Files::initialize(); > $self->CGI::Portable::Request::initialize(); > $self->CGI::Portable::Response::initialize(); Yeah, would have been nice if it called all those without having to be listed, wouldn't it? I think NEXT.pm is the official solution there. Have you used it? -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From jeremygwa at hotmail.com Sun Feb 23 18:56:48 2003 From: jeremygwa at hotmail.com (Jeremy Aiyadurai) Date: Wed Aug 4 00:11:16 2004 Subject: Perl 5.8 threads and sockets problem Message-ID: Hello all, I am new to the group. I have a problem involving sockets and threads. Basically, I want to be able to do two or more pop3 sessions simultaniously using a list of different pop3 accounts. my problem is, I can logon to the first account, but when it comes to the second account's turn (in the second thread), the socket cannot be created. I am new to using threads and have little knowledge of sockets. Your Help is much appreciated, Thanks, Jeremy A. Below is my test script I am having trouble with. #----------------------------------------------------- use threads; use Win32; use IO::Socket qw(:DEFAULT :crlf); my @thr; my @Data; $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => "110", 'LOGIN' => "account1", 'PASS' => "******" }; $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", 'PORT' => "110", 'LOGIN' => "account2", 'PASS' => "*****" }; my $i = 0; sub Startup { while (1) { Win32::Sleep(4000); foreach my $account (@Data) { if(!open(T,"".$account->{'UID'}.".acc")) { Win32::Sleep(40); if($i != 0) { $i = $i + 1; } $thr[$i] = threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account->{'PORT'},$account->{'LOGIN'},$account->{'PASS'}); $thr[$i]->join; }else { close(T); } $i = $i - 1; } } @AC = -1; } Startup(); sub go($$$$$) { print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n"; my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => "$_[1]", PeerPort => $_[2], Timeout => 60) or pop3CError ($_[1],$_[2]); open(X,">".$_[1].".acc"); close(X); print "in $_[1]\n"; sleep(1); pop3close($pop3C); $pop3C = undef; unlink($_[1].".acc"); } sub pop3CError ($$) { print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; exit; } sub pop3close ($) { if ($_[0]) { shutdown ($_[0], 2); } } #----------------------------------------------------- _________________________________________________________________ The new MSN 8: smart spam protection and 2 months FREE* http://join.msn.com/?page=features/junkmail From abez at abez.ca Sun Feb 23 20:38:16 2003 From: abez at abez.ca (abez) Date: Wed Aug 4 00:11:16 2004 Subject: Perl 5.8 threads and sockets problem In-Reply-To: References: Message-ID: First of all try threads->create, rather than new. Other than that I'm too dizzy to really help right now (flu). On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > > Hello all, > > I am new to the group. > I have a problem involving sockets and threads. > > Basically, I want to be able to do two or more pop3 sessions simultaniously > using a list of different pop3 accounts. > my problem is, I can logon to the first account, but when > it comes to the second account's turn (in the second thread), the socket > cannot be created. > > I am new to using threads and have little knowledge of sockets. > > Your Help is much appreciated, > > Thanks, > > Jeremy A. > > Below is my test script I am having trouble with. > > > #----------------------------------------------------- > use threads; > use Win32; > use IO::Socket qw(:DEFAULT :crlf); > > > my @thr; > my @Data; > $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => "110", > 'LOGIN' => "account1", 'PASS' => "******" }; > $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", 'PORT' => "110", > 'LOGIN' => "account2", 'PASS' => "*****" }; > my $i = 0; > > sub Startup { > while (1) { > Win32::Sleep(4000); > foreach my $account (@Data) > { > if(!open(T,"".$account->{'UID'}.".acc")) > { > Win32::Sleep(40); > if($i != 0) > { > $i = $i + 1; > } > $thr[$i] = > threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account->{'PORT'},$account->{'LOGIN'},$account->{'PASS'}); > $thr[$i]->join; > }else > { > close(T); > } > $i = $i - 1; > > } > } > @AC = -1; > } > > Startup(); > > > > sub go($$$$$) { > print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n"; > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => "$_[1]", > PeerPort => $_[2], Timeout => 60) or pop3CError ($_[1],$_[2]); > open(X,">".$_[1].".acc"); > close(X); > print "in $_[1]\n"; > sleep(1); > pop3close($pop3C); > $pop3C = undef; > unlink($_[1].".acc"); > } > > > sub pop3CError ($$) { > > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; > exit; > > } > > > sub pop3close ($) { > if ($_[0]) { > shutdown ($_[0], 2); > } > } > #----------------------------------------------------- > > > > > > _________________________________________________________________ > The new MSN 8: smart spam protection and 2 months FREE* > http://join.msn.com/?page=features/junkmail > -- abez ------------------------------------------ http://www.abez.ca/ Abram Hindle (abez@abez.ca) ------------------------------------------ abez From jeremygwa at hotmail.com Sun Feb 23 22:03:53 2003 From: jeremygwa at hotmail.com (Jeremy Aiyadurai) Date: Wed Aug 4 00:11:16 2004 Subject: Perl 5.8 threads and sockets problem Message-ID: hi All, Thanks for your help so far. I tried threads->create, it made no difference, as mentioned in the manpage, "The new() method is an alias for create(). " Your Help is much appreciated, thanks Jeremy A. >From: abez >To: Jeremy Aiyadurai >CC: victoria-pm@pm.org >Subject: Re: Perl 5.8 threads and sockets problem >Date: Sun, 23 Feb 2003 18:38:16 -0800 (PST) > > >First of all try threads->create, rather than new. Other than that I'm too >dizzy to really help right now (flu). > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > > > > > Hello all, > > > > I am new to the group. > > I have a problem involving sockets and threads. > > > > Basically, I want to be able to do two or more pop3 sessions >simultaniously > > using a list of different pop3 accounts. > > my problem is, I can logon to the first account, but when > > it comes to the second account's turn (in the second thread), the socket > > cannot be created. > > > > I am new to using threads and have little knowledge of sockets. > > > > Your Help is much appreciated, > > > > Thanks, > > > > Jeremy A. > > > > Below is my test script I am having trouble with. > > > > > > #----------------------------------------------------- > > use threads; > > use Win32; > > use IO::Socket qw(:DEFAULT :crlf); > > > > > > my @thr; > > my @Data; > > $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => >"110", > > 'LOGIN' => "account1", 'PASS' => "******" }; > > $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", 'PORT' => "110", > > 'LOGIN' => "account2", 'PASS' => "*****" }; > > my $i = 0; > > > > sub Startup { > > while (1) { > > Win32::Sleep(4000); > > foreach my $account (@Data) > > { > > if(!open(T,"".$account->{'UID'}.".acc")) > > { > > Win32::Sleep(40); > > if($i != 0) > > { > > $i = $i + 1; > > } > > $thr[$i] = > > >threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account->{'PORT'},$account->{'LOGIN'},$account->{'PASS'}); > > $thr[$i]->join; > > }else > > { > > close(T); > > } > > $i = $i - 1; > > > > } > > } > > @AC = -1; > > } > > > > Startup(); > > > > > > > > sub go($$$$$) { > > print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n"; > > > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => "$_[1]", > > PeerPort => $_[2], Timeout => 60) or pop3CError ($_[1],$_[2]); > > open(X,">".$_[1].".acc"); > > close(X); > > print "in $_[1]\n"; > > sleep(1); > > pop3close($pop3C); > > $pop3C = undef; > > unlink($_[1].".acc"); > > } > > > > > > sub pop3CError ($$) { > > > > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; > > exit; > > > > } > > > > > > sub pop3close ($) { > > if ($_[0]) { > > shutdown ($_[0], 2); > > } > > } > > #----------------------------------------------------- > > > > > > > > > > > > _________________________________________________________________ > > The new MSN 8: smart spam protection and 2 months FREE* > > http://join.msn.com/?page=features/junkmail > > > >-- >abez ------------------------------------------ >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >------------------------------------------ abez _________________________________________________________________ Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail From abez at abez.ca Sun Feb 23 22:35:24 2003 From: abez at abez.ca (abez) Date: Wed Aug 4 00:11:16 2004 Subject: Perl 5.8 threads and sockets problem In-Reply-To: References: Message-ID: Here's what I'd do: use IO::Socket qw(:DEFAULT :crlf); my @thr = (); my @Data = ( { 'UID' => "abez", 'SVR' => "lycos.com", 'PORT' => "80", 'LOGIN' => "abez", 'PASS' => "******" }, { 'UID' => "casper", 'SVR' => "www.metafilter.com", 'PORT' => "80", 'LOGIN' => "casper", 'PASS' => "*****" }, ); my $i = 0; Startup(); foreach my $account (@Data) { $str = " rm -f $account->{UID}.acc "; `$str`; } $| = 0; sub Startup { for (;;) { #Win32::Sleep(4000); foreach my $account (@Data) { #if (-f $account->{'UID'}.".acc") { # next; #} print "Forking $account->{UID}\n"; my $pid = fork(); if ($pid==0) { #child print "Child $account->{UID}\n"; go($account); exit(); } } sleep(10); } } sub go($$$$$) { my $account = shift; my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => $account->{SVR}, PeerPort => $account->{PORT} , Timeout => 60) or pop3CError ($account->{SVR},$account->{PORT}); open(X,">".$account->{UID}.".acc"); close(X); print "in $account->{UID}\n"; print $pop3C "GET /\n"; my @out = <$pop3C>; print join("",@out[0..10]),"\n"; $pop3C->close; $pop3C = undef; unlink($_[1].".acc"); } sub pop3CError ($$) { print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; exit; } On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > hi All, > > Thanks for your help so far. > > I tried threads->create, it made no difference, > as mentioned in the manpage, "The new() method is an alias for create(). " > > Your Help is much appreciated, > thanks > > Jeremy A. > > >From: abez > >To: Jeremy Aiyadurai > >CC: victoria-pm@pm.org > >Subject: Re: Perl 5.8 threads and sockets problem > >Date: Sun, 23 Feb 2003 18:38:16 -0800 (PST) > > > > > >First of all try threads->create, rather than new. Other than that I'm too > >dizzy to really help right now (flu). > > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > > > > > > > > Hello all, > > > > > > I am new to the group. > > > I have a problem involving sockets and threads. > > > > > > Basically, I want to be able to do two or more pop3 sessions > >simultaniously > > > using a list of different pop3 accounts. > > > my problem is, I can logon to the first account, but when > > > it comes to the second account's turn (in the second thread), the socket > > > cannot be created. > > > > > > I am new to using threads and have little knowledge of sockets. > > > > > > Your Help is much appreciated, > > > > > > Thanks, > > > > > > Jeremy A. > > > > > > Below is my test script I am having trouble with. > > > > > > > > > #----------------------------------------------------- > > > use threads; > > > use Win32; > > > use IO::Socket qw(:DEFAULT :crlf); > > > > > > > > > my @thr; > > > my @Data; > > > $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => > >"110", > > > 'LOGIN' => "account1", 'PASS' => "******" }; > > > $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", 'PORT' => "110", > > > 'LOGIN' => "account2", 'PASS' => "*****" }; > > > my $i = 0; > > > > > > sub Startup { > > > while (1) { > > > Win32::Sleep(4000); > > > foreach my $account (@Data) > > > { > > > if(!open(T,"".$account->{'UID'}.".acc")) > > > { > > > Win32::Sleep(40); > > > if($i != 0) > > > { > > > $i = $i + 1; > > > } > > > $thr[$i] = > > > > >threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account->{'PORT'},$account->{'LOGIN'},$account->{'PASS'}); > > > $thr[$i]->join; > > > }else > > > { > > > close(T); > > > } > > > $i = $i - 1; > > > > > > } > > > } > > > @AC = -1; > > > } > > > > > > Startup(); > > > > > > > > > > > > sub go($$$$$) { > > > print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n"; > > > > > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => "$_[1]", > > > PeerPort => $_[2], Timeout => 60) or pop3CError ($_[1],$_[2]); > > > open(X,">".$_[1].".acc"); > > > close(X); > > > print "in $_[1]\n"; > > > sleep(1); > > > pop3close($pop3C); > > > $pop3C = undef; > > > unlink($_[1].".acc"); > > > } > > > > > > > > > sub pop3CError ($$) { > > > > > > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; > > > exit; > > > > > > } > > > > > > > > > sub pop3close ($) { > > > if ($_[0]) { > > > shutdown ($_[0], 2); > > > } > > > } > > > #----------------------------------------------------- > > > > > > > > > > > > > > > > > > _________________________________________________________________ > > > The new MSN 8: smart spam protection and 2 months FREE* > > > http://join.msn.com/?page=features/junkmail > > > > > > >-- > >abez ------------------------------------------ > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) > >------------------------------------------ abez > > > _________________________________________________________________ > Add photos to your messages with MSN 8. Get 2 months FREE*. > http://join.msn.com/?page=features/featuredemail > -- abez ------------------------------------------ http://www.abez.ca/ Abram Hindle (abez@abez.ca) ------------------------------------------ abez From jeremygwa at hotmail.com Sun Feb 23 23:49:00 2003 From: jeremygwa at hotmail.com (Jeremy Aiyadurai) Date: Wed Aug 4 00:11:16 2004 Subject: Perl 5.8 threads and sockets problem Message-ID: Hi again, Thanks for all your help so far. I monitored my memory usage while running the script. It appears to slowly eat up memory. If i were to run this script day and night as long as I keep my computer on like a server, It would probably crash my system even though I have alot of SDRAM. Also, the script will run for a while, then crash and exit, does this have to do with fork (thread) races? eg. it ends like this " in Jeremy in Jon Forking Jeremy Forking Jon Child Jeremy Child Jon in Jeremy in Jon Forking Jeremy Child Jeremy in Jeremy" - exits here? don't know why? when three jeremy's are in sequence, the program terminates. Your Help is greatly appreciated Thanks, Jeremy A. here is the script now with the prints "Forking $UID","Child $UID" and "in $UID". --------------------------- use IO::Socket qw(:DEFAULT :crlf); use Win32; my @thr = (); my @Data = ( { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => "110", 'LOGIN' => "jerdoe", 'PASS' => "********" }, { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", 'LOGIN' => "jondoe", 'PASS' => "*****" }, ); my $i = 0; Startup(); #foreach my $account (@Data) { # $str = " rm -f $account->{UID}.acc "; # `$str`; #} sub Startup { for (;;) { #Win32::Sleep(4000); $| = 0; foreach my $account (@Data) { #if (-f $account->{'UID'}.".acc") { # next; #} print "Forking $account->{UID}\n"; my $pid = fork(); if ($pid==0) { #child print "Child $account->{UID}\n"; go($account); $account = undef; exit(); } } sleep(1); } } sub go() { my $ac = shift; my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => $ac->{SVR}, PeerPort => $ac->{PORT} , Timeout => 0) or pop3CError ($ac->{SVR},$ac->{PORT}); open(X,">".$ac->{UID}.".acc"); close(X); print "in $ac->{UID}\n"; Win32::Sleep(4000); $pop3C->close; $ac->{'UID'} = undef; $ac->{'SVR'} = undef; $ac->{'PORT'} = undef; $ac->{'LOGIN'} = undef; $ac->{'PASS'} = undef; $pop3C = undef; unlink($_[1].".acc"); } sub pop3CError ($$) { print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; exit; } >From: abez >To: Jeremy Aiyadurai >CC: victoria-pm@pm.org >Subject: Re: Perl 5.8 threads and sockets problem >Date: Sun, 23 Feb 2003 20:35:24 -0800 (PST) > > > >Here's what I'd do: > >use IO::Socket qw(:DEFAULT :crlf); > >my @thr = (); >my @Data = ( > { 'UID' => "abez", 'SVR' => "lycos.com", 'PORT' => "80", >'LOGIN' => "abez", 'PASS' => "******" }, > { 'UID' => "casper", 'SVR' => "www.metafilter.com", 'PORT' => "80", >'LOGIN' => "casper", 'PASS' => "*****" }, >); >my $i = 0; > >Startup(); > >foreach my $account (@Data) { > $str = " rm -f $account->{UID}.acc "; > `$str`; >} > >$| = 0; >sub Startup { > for (;;) { > #Win32::Sleep(4000); > foreach my $account (@Data) { > #if (-f $account->{'UID'}.".acc") { > # next; > #} > print "Forking $account->{UID}\n"; > my $pid = fork(); > if ($pid==0) { #child > print "Child $account->{UID}\n"; > go($account); > exit(); > } > } > sleep(10); > } > } > > > > >sub go($$$$$) { > my $account = shift; > >my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > $account->{SVR}, > PeerPort => $account->{PORT} , Timeout => 60) > or pop3CError ($account->{SVR},$account->{PORT}); >open(X,">".$account->{UID}.".acc"); >close(X); >print "in $account->{UID}\n"; >print $pop3C "GET /\n"; >my @out = <$pop3C>; >print join("",@out[0..10]),"\n"; >$pop3C->close; > >$pop3C = undef; >unlink($_[1].".acc"); >} > >sub pop3CError ($$) { > >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >exit; > >} > > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > > > hi All, > > > > Thanks for your help so far. > > > > I tried threads->create, it made no difference, > > as mentioned in the manpage, "The new() method is an alias for create(). >" > > > > Your Help is much appreciated, > > thanks > > > > Jeremy A. > > > > >From: abez > > >To: Jeremy Aiyadurai > > >CC: victoria-pm@pm.org > > >Subject: Re: Perl 5.8 threads and sockets problem > > >Date: Sun, 23 Feb 2003 18:38:16 -0800 (PST) > > > > > > > > >First of all try threads->create, rather than new. Other than that I'm >too > > >dizzy to really help right now (flu). > > > > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > > > > > > > > > > > Hello all, > > > > > > > > I am new to the group. > > > > I have a problem involving sockets and threads. > > > > > > > > Basically, I want to be able to do two or more pop3 sessions > > >simultaniously > > > > using a list of different pop3 accounts. > > > > my problem is, I can logon to the first account, but when > > > > it comes to the second account's turn (in the second thread), the >socket > > > > cannot be created. > > > > > > > > I am new to using threads and have little knowledge of sockets. > > > > > > > > Your Help is much appreciated, > > > > > > > > Thanks, > > > > > > > > Jeremy A. > > > > > > > > Below is my test script I am having trouble with. > > > > > > > > > > > > #----------------------------------------------------- > > > > use threads; > > > > use Win32; > > > > use IO::Socket qw(:DEFAULT :crlf); > > > > > > > > > > > > my @thr; > > > > my @Data; > > > > $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => > > >"110", > > > > 'LOGIN' => "account1", 'PASS' => "******" }; > > > > $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", 'PORT' => >"110", > > > > 'LOGIN' => "account2", 'PASS' => "*****" }; > > > > my $i = 0; > > > > > > > > sub Startup { > > > > while (1) { > > > > Win32::Sleep(4000); > > > > foreach my $account (@Data) > > > > { > > > > if(!open(T,"".$account->{'UID'}.".acc")) > > > > { > > > > Win32::Sleep(40); > > > > if($i != 0) > > > > { > > > > $i = $i + 1; > > > > } > > > > $thr[$i] = > > > > > > > >threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account->{'PORT'},$account->{'LOGIN'},$account->{'PASS'}); > > > > $thr[$i]->join; > > > > }else > > > > { > > > > close(T); > > > > } > > > > $i = $i - 1; > > > > > > > > } > > > > } > > > > @AC = -1; > > > > } > > > > > > > > Startup(); > > > > > > > > > > > > > > > > sub go($$$$$) { > > > > print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n"; > > > > > > > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >"$_[1]", > > > > PeerPort => $_[2], Timeout => 60) or pop3CError ($_[1],$_[2]); > > > > open(X,">".$_[1].".acc"); > > > > close(X); > > > > print "in $_[1]\n"; > > > > sleep(1); > > > > pop3close($pop3C); > > > > $pop3C = undef; > > > > unlink($_[1].".acc"); > > > > } > > > > > > > > > > > > sub pop3CError ($$) { > > > > > > > > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; > > > > exit; > > > > > > > > } > > > > > > > > > > > > sub pop3close ($) { > > > > if ($_[0]) { > > > > shutdown ($_[0], 2); > > > > } > > > > } > > > > #----------------------------------------------------- > > > > > > > > > > > > > > > > > > > > > > > > _________________________________________________________________ > > > > The new MSN 8: smart spam protection and 2 months FREE* > > > > http://join.msn.com/?page=features/junkmail > > > > > > > > > >-- > > >abez ------------------------------------------ > > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) > > >------------------------------------------ abez > > > > > > _________________________________________________________________ > > Add photos to your messages with MSN 8. Get 2 months FREE*. > > http://join.msn.com/?page=features/featuredemail > > > >-- >abez ------------------------------------------ >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >------------------------------------------ abez _________________________________________________________________ Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail From abez at abez.ca Mon Feb 24 00:10:03 2003 From: abez at abez.ca (abez) Date: Wed Aug 4 00:11:16 2004 Subject: Perl 5.8 threads and sockets problem In-Reply-To: References: Message-ID: Well uncomment these lines, so that you "locking" works. > #if (-f $account->{'UID'}.".acc") { > # next; > #} I don't know WIN32 too well to guess about the memory but you might want to print before that exit where $account = undef; exit; Just print you're closing you might get better information. Also print debugging info to STDERR if possible it's default unbuffered. call wait() before you call sleep(1) and it will make sure your processes aren't zombified. On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > > Hi again, > > Thanks for all your help so far. > I monitored my memory usage while running the script. > It appears to slowly eat up memory. If i were to run this script day and > night as long as I keep my computer on like a server, It would probably > crash my system even though I have alot of SDRAM. > Also, the script will run for a while, then crash and exit, does this have > to do with fork (thread) races? > eg. it ends like this > " > in Jeremy > in Jon > Forking Jeremy > Forking Jon > Child Jeremy > Child Jon > in Jeremy > in Jon > Forking Jeremy > Child Jeremy > in Jeremy" - exits here? don't know why? when three jeremy's are in > sequence, the program terminates. > > Your Help is greatly appreciated > > Thanks, > Jeremy A. > > here is the script now with the prints "Forking $UID","Child $UID" and "in > $UID". > --------------------------- > use IO::Socket qw(:DEFAULT :crlf); > use Win32; > > > my @thr = (); > my @Data = ( > { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => "110", > 'LOGIN' => "jerdoe", 'PASS' => "********" }, > { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", > 'LOGIN' => "jondoe", 'PASS' => "*****" }, > ); > my $i = 0; > > Startup(); > > #foreach my $account (@Data) { > # $str = " rm -f $account->{UID}.acc "; > # `$str`; > #} > > > sub Startup { > for (;;) { > #Win32::Sleep(4000); > $| = 0; > foreach my $account (@Data) { > #if (-f $account->{'UID'}.".acc") { > # next; > #} > print "Forking $account->{UID}\n"; > my $pid = fork(); > if ($pid==0) { #child > print "Child $account->{UID}\n"; > go($account); > $account = undef; > exit(); > } > > } > sleep(1); > } > } > > > > > sub go() { > my $ac = shift; > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > $ac->{SVR}, > PeerPort => $ac->{PORT} , Timeout => 0) > or pop3CError ($ac->{SVR},$ac->{PORT}); > open(X,">".$ac->{UID}.".acc"); > close(X); > print "in $ac->{UID}\n"; > Win32::Sleep(4000); > $pop3C->close; > $ac->{'UID'} = undef; > $ac->{'SVR'} = undef; > $ac->{'PORT'} = undef; > $ac->{'LOGIN'} = undef; > $ac->{'PASS'} = undef; > $pop3C = undef; > unlink($_[1].".acc"); > } > > sub pop3CError ($$) { > > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; > exit; > > } > > > > > >From: abez > >To: Jeremy Aiyadurai > >CC: victoria-pm@pm.org > >Subject: Re: Perl 5.8 threads and sockets problem > >Date: Sun, 23 Feb 2003 20:35:24 -0800 (PST) > > > > > > > >Here's what I'd do: > > > >use IO::Socket qw(:DEFAULT :crlf); > > > >my @thr = (); > >my @Data = ( > > { 'UID' => "abez", 'SVR' => "lycos.com", 'PORT' => "80", > >'LOGIN' => "abez", 'PASS' => "******" }, > > { 'UID' => "casper", 'SVR' => "www.metafilter.com", 'PORT' => "80", > >'LOGIN' => "casper", 'PASS' => "*****" }, > >); > >my $i = 0; > > > >Startup(); > > > >foreach my $account (@Data) { > > $str = " rm -f $account->{UID}.acc "; > > `$str`; > >} > > > >$| = 0; > >sub Startup { > > for (;;) { > > #Win32::Sleep(4000); > > foreach my $account (@Data) { > > #if (-f $account->{'UID'}.".acc") { > > # next; > > #} > > print "Forking $account->{UID}\n"; > > my $pid = fork(); > > if ($pid==0) { #child > > print "Child $account->{UID}\n"; > > go($account); > > exit(); > > } > > } > > sleep(10); > > } > > } > > > > > > > > > >sub go($$$$$) { > > my $account = shift; > > > >my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > > $account->{SVR}, > > PeerPort => $account->{PORT} , Timeout => 60) > > or pop3CError ($account->{SVR},$account->{PORT}); > >open(X,">".$account->{UID}.".acc"); > >close(X); > >print "in $account->{UID}\n"; > >print $pop3C "GET /\n"; > >my @out = <$pop3C>; > >print join("",@out[0..10]),"\n"; > >$pop3C->close; > > > >$pop3C = undef; > >unlink($_[1].".acc"); > >} > > > >sub pop3CError ($$) { > > > >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; > >exit; > > > >} > > > > > > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > > > > > hi All, > > > > > > Thanks for your help so far. > > > > > > I tried threads->create, it made no difference, > > > as mentioned in the manpage, "The new() method is an alias for create(). > >" > > > > > > Your Help is much appreciated, > > > thanks > > > > > > Jeremy A. > > > > > > >From: abez > > > >To: Jeremy Aiyadurai > > > >CC: victoria-pm@pm.org > > > >Subject: Re: Perl 5.8 threads and sockets problem > > > >Date: Sun, 23 Feb 2003 18:38:16 -0800 (PST) > > > > > > > > > > > >First of all try threads->create, rather than new. Other than that I'm > >too > > > >dizzy to really help right now (flu). > > > > > > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > > > > > > > > > > > > > > Hello all, > > > > > > > > > > I am new to the group. > > > > > I have a problem involving sockets and threads. > > > > > > > > > > Basically, I want to be able to do two or more pop3 sessions > > > >simultaniously > > > > > using a list of different pop3 accounts. > > > > > my problem is, I can logon to the first account, but when > > > > > it comes to the second account's turn (in the second thread), the > >socket > > > > > cannot be created. > > > > > > > > > > I am new to using threads and have little knowledge of sockets. > > > > > > > > > > Your Help is much appreciated, > > > > > > > > > > Thanks, > > > > > > > > > > Jeremy A. > > > > > > > > > > Below is my test script I am having trouble with. > > > > > > > > > > > > > > > #----------------------------------------------------- > > > > > use threads; > > > > > use Win32; > > > > > use IO::Socket qw(:DEFAULT :crlf); > > > > > > > > > > > > > > > my @thr; > > > > > my @Data; > > > > > $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => > > > >"110", > > > > > 'LOGIN' => "account1", 'PASS' => "******" }; > > > > > $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", 'PORT' => > >"110", > > > > > 'LOGIN' => "account2", 'PASS' => "*****" }; > > > > > my $i = 0; > > > > > > > > > > sub Startup { > > > > > while (1) { > > > > > Win32::Sleep(4000); > > > > > foreach my $account (@Data) > > > > > { > > > > > if(!open(T,"".$account->{'UID'}.".acc")) > > > > > { > > > > > Win32::Sleep(40); > > > > > if($i != 0) > > > > > { > > > > > $i = $i + 1; > > > > > } > > > > > $thr[$i] = > > > > > > > > > > >threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account->{'PORT'},$account->{'LOGIN'},$account->{'PASS'}); > > > > > $thr[$i]->join; > > > > > }else > > > > > { > > > > > close(T); > > > > > } > > > > > $i = $i - 1; > > > > > > > > > > } > > > > > } > > > > > @AC = -1; > > > > > } > > > > > > > > > > Startup(); > > > > > > > > > > > > > > > > > > > > sub go($$$$$) { > > > > > print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n"; > > > > > > > > > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > >"$_[1]", > > > > > PeerPort => $_[2], Timeout => 60) or pop3CError ($_[1],$_[2]); > > > > > open(X,">".$_[1].".acc"); > > > > > close(X); > > > > > print "in $_[1]\n"; > > > > > sleep(1); > > > > > pop3close($pop3C); > > > > > $pop3C = undef; > > > > > unlink($_[1].".acc"); > > > > > } > > > > > > > > > > > > > > > sub pop3CError ($$) { > > > > > > > > > > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; > > > > > exit; > > > > > > > > > > } > > > > > > > > > > > > > > > sub pop3close ($) { > > > > > if ($_[0]) { > > > > > shutdown ($_[0], 2); > > > > > } > > > > > } > > > > > #----------------------------------------------------- > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > _________________________________________________________________ > > > > > The new MSN 8: smart spam protection and 2 months FREE* > > > > > http://join.msn.com/?page=features/junkmail > > > > > > > > > > > > >-- > > > >abez ------------------------------------------ > > > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) > > > >------------------------------------------ abez > > > > > > > > > _________________________________________________________________ > > > Add photos to your messages with MSN 8. Get 2 months FREE*. > > > http://join.msn.com/?page=features/featuredemail > > > > > > >-- > >abez ------------------------------------------ > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) > >------------------------------------------ abez > > > _________________________________________________________________ > Help STOP SPAM with the new MSN 8 and get 2 months FREE* > http://join.msn.com/?page=features/junkmail > -- abez ------------------------------------------ http://www.abez.ca/ Abram Hindle (abez@abez.ca) ------------------------------------------ abez From peter at PSDT.com Sun Feb 23 09:16:00 2003 From: peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:16 2004 Subject: Victoria Perl Mongers Meeting tomorrow Message-ID: <4.3.2.7.2.20030220111540.00bd5430@shell2.webquarry.com> Victoria.pm will meet tomorrow, Monday Feb 24, 7pm, at UVic's Clearihue A206. Nathanael Kuipers will speak on: "Lord of the Strings: Perl in Biological Applications." For those unfamiliar with UVic, see grid C3. Parking can be found at the top centre of B3. If you don't know how to get to UVic - welcome to Victoria - see . Other topics to be covered as time permits; make requests for anything particular. (Courtesy copy to VLUG members by permission of the list manager. Victoria.pm's home page is .) -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From nkuipers at uvic.ca Mon Feb 24 20:06:41 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:16 2004 Subject: might be too late... Message-ID: <3E5AD7E4@wm2.uvic.ca> ..but here's hoping someone brings a laptop; my presentation is of course in powerpoint format and i just realized y'all might have reasonably assumed i have a laptop.... From jeremygwa at hotmail.com Tue Feb 25 18:28:55 2003 From: jeremygwa at hotmail.com (Jeremy Aiyadurai) Date: Wed Aug 4 00:11:16 2004 Subject: Perl 5.8 threads and sockets problem Message-ID: Hi all, Thanks for all your help so far. I am still having having problems with the forking. the script will only run for 30 or so seconds, before it exits. I am stumped on how to keep it running continously. The following is the code ............................................... use IO::Socket qw(:DEFAULT :crlf); my $pop3C; my @thr = (); my @Data = ( { 'UID' => "Jeremy", 'SVR' => "mail.h.y", 'PORT' => "110", 'LOGIN' => "jerdoe", 'PASS' => "******" }, { 'UID' => "Jon", 'SVR' => "mail.h.t", 'PORT' => "110", 'LOGIN' => "jondoe", 'PASS' => "****" }, ); my $i = 0; Startup(); sub Startup { $| = 0; for (;;) { foreach my $account (@Data) { if (-f $account->{'UID'}.".acc") { next; } print "Forking $account->{UID}\n"; my $pid = fork(); if ($pid == 0){ # in child print "Child $account->{UID}\n"; go($account); $account = undef; exit(0); } } sleep(1); } } sub go() { my $ac = shift; $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => $ac->{SVR}, PeerPort => $ac->{PORT} , Timeout => 0) or pop3CError ($ac->{SVR},$ac->{PORT}); open(X,">".$ac->{UID}.".acc"); close(X); print "in $ac->{UID}\n"; $pop3C->close; unlink($ac->{'UID'}.".acc"); $ac->{'UID'} = undef; $ac->{'SVR'} = undef; $ac->{'PORT'} = undef; $ac->{'LOGIN'} = undef; $ac->{'PASS'} = undef; $pop3C = undef; } sub pop3CError ($$) { print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; exit; } .................................................. Your help is much appreciated. Thanks, Jeremy A. >From: abez >To: Jeremy Aiyadurai >CC: victoria-pm@pm.org >Subject: Re: Perl 5.8 threads and sockets problem >Date: Sun, 23 Feb 2003 22:10:03 -0800 (PST) > > >Well uncomment these lines, so that you "locking" works. > > #if (-f $account->{'UID'}.".acc") { > > # next; > > #} > >I don't know WIN32 too well to guess about the memory but you might want to >print before that exit where $account = undef; exit; Just print you're >closing >you might get better information. > >Also print debugging info to STDERR if possible it's default unbuffered. > >call wait() before you call sleep(1) and it will make sure your processes >aren't zombified. > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > > > > > Hi again, > > > > Thanks for all your help so far. > > I monitored my memory usage while running the script. > > It appears to slowly eat up memory. If i were to run this script day and > > night as long as I keep my computer on like a server, It would probably > > crash my system even though I have alot of SDRAM. > > Also, the script will run for a while, then crash and exit, does this >have > > to do with fork (thread) races? > > eg. it ends like this > > " > > in Jeremy > > in Jon > > Forking Jeremy > > Forking Jon > > Child Jeremy > > Child Jon > > in Jeremy > > in Jon > > Forking Jeremy > > Child Jeremy > > in Jeremy" - exits here? don't know why? when three jeremy's are in > > sequence, the program terminates. > > > > Your Help is greatly appreciated > > > > Thanks, > > Jeremy A. > > > > here is the script now with the prints "Forking $UID","Child $UID" and >"in > > $UID". > > --------------------------- > > use IO::Socket qw(:DEFAULT :crlf); > > use Win32; > > > > > > my @thr = (); > > my @Data = ( > > { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => "110", > > 'LOGIN' => "jerdoe", 'PASS' => "********" }, > > { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", > > 'LOGIN' => "jondoe", 'PASS' => "*****" }, > > ); > > my $i = 0; > > > > Startup(); > > > > #foreach my $account (@Data) { > > # $str = " rm -f $account->{UID}.acc "; > > # `$str`; > > #} > > > > > > sub Startup { > > for (;;) { > > #Win32::Sleep(4000); > > $| = 0; > > foreach my $account (@Data) { > > #if (-f $account->{'UID'}.".acc") { > > # next; > > #} > > print "Forking $account->{UID}\n"; > > my $pid = fork(); > > if ($pid==0) { #child > > print "Child $account->{UID}\n"; > > go($account); > > $account = undef; > > exit(); > > } > > > > } > > sleep(1); > > } > > } > > > > > > > > > > sub go() { > > my $ac = shift; > > > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > > $ac->{SVR}, > > PeerPort => $ac->{PORT} , Timeout => 0) > > or pop3CError ($ac->{SVR},$ac->{PORT}); > > open(X,">".$ac->{UID}.".acc"); > > close(X); > > print "in $ac->{UID}\n"; > > Win32::Sleep(4000); > > $pop3C->close; > > $ac->{'UID'} = undef; > > $ac->{'SVR'} = undef; > > $ac->{'PORT'} = undef; > > $ac->{'LOGIN'} = undef; > > $ac->{'PASS'} = undef; > > $pop3C = undef; > > unlink($_[1].".acc"); > > } > > > > sub pop3CError ($$) { > > > > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; > > exit; > > > > } > > > > > > > > > > >From: abez > > >To: Jeremy Aiyadurai > > >CC: victoria-pm@pm.org > > >Subject: Re: Perl 5.8 threads and sockets problem > > >Date: Sun, 23 Feb 2003 20:35:24 -0800 (PST) > > > > > > > > > > > >Here's what I'd do: > > > > > >use IO::Socket qw(:DEFAULT :crlf); > > > > > >my @thr = (); > > >my @Data = ( > > > { 'UID' => "abez", 'SVR' => "lycos.com", 'PORT' => "80", > > >'LOGIN' => "abez", 'PASS' => "******" }, > > > { 'UID' => "casper", 'SVR' => "www.metafilter.com", 'PORT' => "80", > > >'LOGIN' => "casper", 'PASS' => "*****" }, > > >); > > >my $i = 0; > > > > > >Startup(); > > > > > >foreach my $account (@Data) { > > > $str = " rm -f $account->{UID}.acc "; > > > `$str`; > > >} > > > > > >$| = 0; > > >sub Startup { > > > for (;;) { > > > #Win32::Sleep(4000); > > > foreach my $account (@Data) { > > > #if (-f $account->{'UID'}.".acc") { > > > # next; > > > #} > > > print "Forking $account->{UID}\n"; > > > my $pid = fork(); > > > if ($pid==0) { #child > > > print "Child $account->{UID}\n"; > > > go($account); > > > exit(); > > > } > > > } > > > sleep(10); > > > } > > > } > > > > > > > > > > > > > > >sub go($$$$$) { > > > my $account = shift; > > > > > >my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > > > $account->{SVR}, > > > PeerPort => $account->{PORT} , Timeout => 60) > > > or pop3CError ($account->{SVR},$account->{PORT}); > > >open(X,">".$account->{UID}.".acc"); > > >close(X); > > >print "in $account->{UID}\n"; > > >print $pop3C "GET /\n"; > > >my @out = <$pop3C>; > > >print join("",@out[0..10]),"\n"; > > >$pop3C->close; > > > > > >$pop3C = undef; > > >unlink($_[1].".acc"); > > >} > > > > > >sub pop3CError ($$) { > > > > > >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; > > >exit; > > > > > >} > > > > > > > > > > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > > > > > > > hi All, > > > > > > > > Thanks for your help so far. > > > > > > > > I tried threads->create, it made no difference, > > > > as mentioned in the manpage, "The new() method is an alias for >create(). > > >" > > > > > > > > Your Help is much appreciated, > > > > thanks > > > > > > > > Jeremy A. > > > > > > > > >From: abez > > > > >To: Jeremy Aiyadurai > > > > >CC: victoria-pm@pm.org > > > > >Subject: Re: Perl 5.8 threads and sockets problem > > > > >Date: Sun, 23 Feb 2003 18:38:16 -0800 (PST) > > > > > > > > > > > > > > >First of all try threads->create, rather than new. Other than that >I'm > > >too > > > > >dizzy to really help right now (flu). > > > > > > > > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > > > > > > > > > > > > > > > > > Hello all, > > > > > > > > > > > > I am new to the group. > > > > > > I have a problem involving sockets and threads. > > > > > > > > > > > > Basically, I want to be able to do two or more pop3 sessions > > > > >simultaniously > > > > > > using a list of different pop3 accounts. > > > > > > my problem is, I can logon to the first account, but when > > > > > > it comes to the second account's turn (in the second thread), >the > > >socket > > > > > > cannot be created. > > > > > > > > > > > > I am new to using threads and have little knowledge of sockets. > > > > > > > > > > > > Your Help is much appreciated, > > > > > > > > > > > > Thanks, > > > > > > > > > > > > Jeremy A. > > > > > > > > > > > > Below is my test script I am having trouble with. > > > > > > > > > > > > > > > > > > #----------------------------------------------------- > > > > > > use threads; > > > > > > use Win32; > > > > > > use IO::Socket qw(:DEFAULT :crlf); > > > > > > > > > > > > > > > > > > my @thr; > > > > > > my @Data; > > > > > > $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' >=> > > > > >"110", > > > > > > 'LOGIN' => "account1", 'PASS' => "******" }; > > > > > > $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", 'PORT' >=> > > >"110", > > > > > > 'LOGIN' => "account2", 'PASS' => "*****" }; > > > > > > my $i = 0; > > > > > > > > > > > > sub Startup { > > > > > > while (1) { > > > > > > Win32::Sleep(4000); > > > > > > foreach my $account (@Data) > > > > > > { > > > > > > if(!open(T,"".$account->{'UID'}.".acc")) > > > > > > { > > > > > > Win32::Sleep(40); > > > > > > if($i != 0) > > > > > > { > > > > > > $i = $i + 1; > > > > > > } > > > > > > $thr[$i] = > > > > > > > > > > > > > > >threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account->{'PORT'},$account->{'LOGIN'},$account->{'PASS'}); > > > > > > $thr[$i]->join; > > > > > > }else > > > > > > { > > > > > > close(T); > > > > > > } > > > > > > $i = $i - 1; > > > > > > > > > > > > } > > > > > > } > > > > > > @AC = -1; > > > > > > } > > > > > > > > > > > > Startup(); > > > > > > > > > > > > > > > > > > > > > > > > sub go($$$$$) { > > > > > > print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n"; > > > > > > > > > > > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > > >"$_[1]", > > > > > > PeerPort => $_[2], Timeout => 60) or pop3CError ($_[1],$_[2]); > > > > > > open(X,">".$_[1].".acc"); > > > > > > close(X); > > > > > > print "in $_[1]\n"; > > > > > > sleep(1); > > > > > > pop3close($pop3C); > > > > > > $pop3C = undef; > > > > > > unlink($_[1].".acc"); > > > > > > } > > > > > > > > > > > > > > > > > > sub pop3CError ($$) { > > > > > > > > > > > > print "Cannot connect to the the Pop3 server:$_[0], >port:$_[1]\n"; > > > > > > exit; > > > > > > > > > > > > } > > > > > > > > > > > > > > > > > > sub pop3close ($) { > > > > > > if ($_[0]) { > > > > > > shutdown ($_[0], 2); > > > > > > } > > > > > > } > > > > > > #----------------------------------------------------- > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > >_________________________________________________________________ > > > > > > The new MSN 8: smart spam protection and 2 months FREE* > > > > > > http://join.msn.com/?page=features/junkmail > > > > > > > > > > > > > > > >-- > > > > >abez ------------------------------------------ > > > > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) > > > > >------------------------------------------ abez > > > > > > > > > > > > _________________________________________________________________ > > > > Add photos to your messages with MSN 8. Get 2 months FREE*. > > > > http://join.msn.com/?page=features/featuredemail > > > > > > > > > >-- > > >abez ------------------------------------------ > > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) > > >------------------------------------------ abez > > > > > > _________________________________________________________________ > > Help STOP SPAM with the new MSN 8 and get 2 months FREE* > > http://join.msn.com/?page=features/junkmail > > > >-- >abez ------------------------------------------ >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >------------------------------------------ abez _________________________________________________________________ Help STOP SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail From Peter at PSDT.com Tue Feb 25 18:37:21 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:16 2004 Subject: Perl 5.8 threads and sockets problem In-Reply-To: Message-ID: <4.3.2.7.2.20030225163314.00be73f0@shell2.webquarry.com> I'm coming in a bit late here. I've no experience of Win32 programming with threads or multiprocessing so this may not be much help. However, I gather that the idea is to have something that keeps testing a POP3 connection (I don't see any login to the accounts despite the fact that the passwords are there). I don't see any use strict or use warnings, which is asking for trouble. And there is no testing of the result of the open(), which is even worse. Insufficient information without those. At 04:28 PM 2/25/03 -0800, Jeremy Aiyadurai wrote: >Hi all, > >Thanks for all your help so far. > >I am still having having problems with the forking. >the script will only run for 30 or so seconds, >before it exits. > >I am stumped on how to keep it running continously. > >The following is the code >............................................... >use IO::Socket qw(:DEFAULT :crlf); > > >my $pop3C; >my @thr = (); >my @Data = ( > { 'UID' => "Jeremy", 'SVR' => "mail.h.y", 'PORT' => "110", >'LOGIN' => "jerdoe", 'PASS' => "******" }, > { 'UID' => "Jon", 'SVR' => "mail.h.t", 'PORT' => "110", >'LOGIN' => "jondoe", 'PASS' => "****" }, >); >my $i = 0; > >Startup(); > > >sub Startup { > $| = 0; > for (;;) { > foreach my $account (@Data) { > if (-f $account->{'UID'}.".acc") { > next; > } > print "Forking $account->{UID}\n"; > my $pid = fork(); > if ($pid == 0){ > # in child > print "Child $account->{UID}\n"; > go($account); > $account = undef; > exit(0); > } > > } > > sleep(1); > } > } > > > >sub go() { > my $ac = shift; > >$pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > $ac->{SVR}, > PeerPort => $ac->{PORT} , Timeout => 0) > or pop3CError ($ac->{SVR},$ac->{PORT}); >open(X,">".$ac->{UID}.".acc"); >close(X); >print "in $ac->{UID}\n"; >$pop3C->close; >unlink($ac->{'UID'}.".acc"); >$ac->{'UID'} = undef; >$ac->{'SVR'} = undef; >$ac->{'PORT'} = undef; >$ac->{'LOGIN'} = undef; >$ac->{'PASS'} = undef; >$pop3C = undef; >} > >sub pop3CError ($$) { > >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >exit; > >} >.................................................. > > >Your help is much appreciated. >Thanks, > >Jeremy A. > > > > > > >>From: abez >>To: Jeremy Aiyadurai >>CC: victoria-pm@pm.org >>Subject: Re: Perl 5.8 threads and sockets problem >>Date: Sun, 23 Feb 2003 22:10:03 -0800 (PST) >> >> >>Well uncomment these lines, so that you "locking" works. >> > #if (-f $account->{'UID'}.".acc") { >> > # next; >> > #} >> >>I don't know WIN32 too well to guess about the memory but you might want to >>print before that exit where $account = undef; exit; Just print >>you're closing >>you might get better information. >> >>Also print debugging info to STDERR if possible it's default unbuffered. >> >>call wait() before you call sleep(1) and it will make sure your processes >>aren't zombified. >> >> >>On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >> >> > >> > Hi again, >> > >> > Thanks for all your help so far. >> > I monitored my memory usage while running the script. >> > It appears to slowly eat up memory. If i were to run this script day and >> > night as long as I keep my computer on like a server, It would probably >> > crash my system even though I have alot of SDRAM. >> > Also, the script will run for a while, then crash and exit, does this have >> > to do with fork (thread) races? >> > eg. it ends like this >> > " >> > in Jeremy >> > in Jon >> > Forking Jeremy >> > Forking Jon >> > Child Jeremy >> > Child Jon >> > in Jeremy >> > in Jon >> > Forking Jeremy >> > Child Jeremy >> > in Jeremy" - exits here? don't know why? when three jeremy's are in >> > sequence, the program terminates. >> > >> > Your Help is greatly appreciated >> > >> > Thanks, >> > Jeremy A. >> > >> > here is the script now with the prints "Forking $UID","Child $UID" and "in >> > $UID". >> > --------------------------- >> > use IO::Socket qw(:DEFAULT :crlf); >> > use Win32; >> > >> > >> > my @thr = (); >> > my @Data = ( >> > { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => "110", >> > 'LOGIN' => "jerdoe", 'PASS' => "********" }, >> > { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", >> > 'LOGIN' => "jondoe", 'PASS' => "*****" }, >> > ); >> > my $i = 0; >> > >> > Startup(); >> > >> > #foreach my $account (@Data) { >> > # $str = " rm -f $account->{UID}.acc "; >> > # `$str`; >> > #} >> > >> > >> > sub Startup { >> > for (;;) { >> > #Win32::Sleep(4000); >> > $| = 0; >> > foreach my $account (@Data) { >> > #if (-f $account->{'UID'}.".acc") { >> > # next; >> > #} >> > print "Forking $account->{UID}\n"; >> > my $pid = fork(); >> > if ($pid==0) { #child >> > print "Child $account->{UID}\n"; >> > go($account); >> > $account = undef; >> > exit(); >> > } >> > >> > } >> > sleep(1); >> > } >> > } >> > >> > >> > >> > >> > sub go() { >> > my $ac = shift; >> > >> > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >> > $ac->{SVR}, >> > PeerPort => $ac->{PORT} , Timeout => 0) >> > or pop3CError ($ac->{SVR},$ac->{PORT}); >> > open(X,">".$ac->{UID}.".acc"); >> > close(X); >> > print "in $ac->{UID}\n"; >> > Win32::Sleep(4000); >> > $pop3C->close; >> > $ac->{'UID'} = undef; >> > $ac->{'SVR'} = undef; >> > $ac->{'PORT'} = undef; >> > $ac->{'LOGIN'} = undef; >> > $ac->{'PASS'} = undef; >> > $pop3C = undef; >> > unlink($_[1].".acc"); >> > } >> > >> > sub pop3CError ($$) { >> > >> > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >> > exit; >> > >> > } >> > >> > >> > >> > >> > >From: abez >> > >To: Jeremy Aiyadurai >> > >CC: victoria-pm@pm.org >> > >Subject: Re: Perl 5.8 threads and sockets problem >> > >Date: Sun, 23 Feb 2003 20:35:24 -0800 (PST) >> > > >> > > >> > > >> > >Here's what I'd do: >> > > >> > >use IO::Socket qw(:DEFAULT :crlf); >> > > >> > >my @thr = (); >> > >my @Data = ( >> > > { 'UID' => "abez", 'SVR' => "lycos.com", 'PORT' => "80", >> > >'LOGIN' => "abez", 'PASS' => "******" }, >> > > { 'UID' => "casper", 'SVR' => "www.metafilter.com", 'PORT' => "80", >> > >'LOGIN' => "casper", 'PASS' => "*****" }, >> > >); >> > >my $i = 0; >> > > >> > >Startup(); >> > > >> > >foreach my $account (@Data) { >> > > $str = " rm -f $account->{UID}.acc "; >> > > `$str`; >> > >} >> > > >> > >$| = 0; >> > >sub Startup { >> > > for (;;) { >> > > #Win32::Sleep(4000); >> > > foreach my $account (@Data) { >> > > #if (-f $account->{'UID'}.".acc") { >> > > # next; >> > > #} >> > > print "Forking $account->{UID}\n"; >> > > my $pid = fork(); >> > > if ($pid==0) { #child >> > > print "Child $account->{UID}\n"; >> > > go($account); >> > > exit(); >> > > } >> > > } >> > > sleep(10); >> > > } >> > > } >> > > >> > > >> > > >> > > >> > >sub go($$$$$) { >> > > my $account = shift; >> > > >> > >my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >> > > $account->{SVR}, >> > > PeerPort => $account->{PORT} , Timeout => 60) >> > > or pop3CError ($account->{SVR},$account->{PORT}); >> > >open(X,">".$account->{UID}.".acc"); >> > >close(X); >> > >print "in $account->{UID}\n"; >> > >print $pop3C "GET /\n"; >> > >my @out = <$pop3C>; >> > >print join("",@out[0..10]),"\n"; >> > >$pop3C->close; >> > > >> > >$pop3C = undef; >> > >unlink($_[1].".acc"); >> > >} >> > > >> > >sub pop3CError ($$) { >> > > >> > >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >> > >exit; >> > > >> > >} >> > > >> > > >> > > >> > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >> > > >> > > > hi All, >> > > > >> > > > Thanks for your help so far. >> > > > >> > > > I tried threads->create, it made no difference, >> > > > as mentioned in the manpage, "The new() method is an alias for >> create(). >> > >" >> > > > >> > > > Your Help is much appreciated, >> > > > thanks >> > > > >> > > > Jeremy A. >> > > > >> > > > >From: abez >> > > > >To: Jeremy Aiyadurai >> > > > >CC: victoria-pm@pm.org >> > > > >Subject: Re: Perl 5.8 threads and sockets problem >> > > > >Date: Sun, 23 Feb 2003 18:38:16 -0800 (PST) >> > > > > >> > > > > >> > > > >First of all try threads->create, rather than new. Other than >> that I'm >> > >too >> > > > >dizzy to really help right now (flu). >> > > > > >> > > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >> > > > > >> > > > > > >> > > > > > Hello all, >> > > > > > >> > > > > > I am new to the group. >> > > > > > I have a problem involving sockets and threads. >> > > > > > >> > > > > > Basically, I want to be able to do two or more pop3 sessions >> > > > >simultaniously >> > > > > > using a list of different pop3 accounts. >> > > > > > my problem is, I can logon to the first account, but when >> > > > > > it comes to the second account's turn (in the second thread), the >> > >socket >> > > > > > cannot be created. >> > > > > > >> > > > > > I am new to using threads and have little knowledge of sockets. >> > > > > > >> > > > > > Your Help is much appreciated, >> > > > > > >> > > > > > Thanks, >> > > > > > >> > > > > > Jeremy A. >> > > > > > >> > > > > > Below is my test script I am having trouble with. >> > > > > > >> > > > > > >> > > > > > #----------------------------------------------------- >> > > > > > use threads; >> > > > > > use Win32; >> > > > > > use IO::Socket qw(:DEFAULT :crlf); >> > > > > > >> > > > > > >> > > > > > my @thr; >> > > > > > my @Data; >> > > > > > $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", >> 'PORT' => >> > > > >"110", >> > > > > > 'LOGIN' => "account1", 'PASS' => "******" }; >> > > > > > $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", 'PORT' => >> > >"110", >> > > > > > 'LOGIN' => "account2", 'PASS' => "*****" }; >> > > > > > my $i = 0; >> > > > > > >> > > > > > sub Startup { >> > > > > > while (1) { >> > > > > > Win32::Sleep(4000); >> > > > > > foreach my $account (@Data) >> > > > > > { >> > > > > > if(!open(T,"".$account->{'UID'}.".acc")) >> > > > > > { >> > > > > > Win32::Sleep(40); >> > > > > > if($i != 0) >> > > > > > { >> > > > > > $i = $i + 1; >> > > > > > } >> > > > > > $thr[$i] = >> > > > > > >> > > > >> > > >threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account-> >> {'PORT'},$account->{'LOGIN'},$account->{'PASS'}); >> > > > > > $thr[$i]->join; >> > > > > > }else >> > > > > > { >> > > > > > close(T); >> > > > > > } >> > > > > > $i = $i - 1; >> > > > > > >> > > > > > } >> > > > > > } >> > > > > > @AC = -1; >> > > > > > } >> > > > > > >> > > > > > Startup(); >> > > > > > >> > > > > > >> > > > > > >> > > > > > sub go($$$$$) { >> > > > > > print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n"; >> > > > > > >> > > > > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >> > >"$_[1]", >> > > > > > PeerPort => $_[2], Timeout => 60) or pop3CError ($_[1],$_[2]); >> > > > > > open(X,">".$_[1].".acc"); >> > > > > > close(X); >> > > > > > print "in $_[1]\n"; >> > > > > > sleep(1); >> > > > > > pop3close($pop3C); >> > > > > > $pop3C = undef; >> > > > > > unlink($_[1].".acc"); >> > > > > > } >> > > > > > >> > > > > > >> > > > > > sub pop3CError ($$) { >> > > > > > >> > > > > > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >> > > > > > exit; >> > > > > > >> > > > > > } >> > > > > > >> > > > > > >> > > > > > sub pop3close ($) { >> > > > > > if ($_[0]) { >> > > > > > shutdown ($_[0], 2); >> > > > > > } >> > > > > > } >> > > > > > #----------------------------------------------------- >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > _________________________________________________________________ >> > > > > > The new MSN 8: smart spam protection and 2 months FREE* >> > > > > > http://join.msn.com/?page=features/junkmail >> > > > > > >> > > > > >> > > > >-- >> > > > >abez ------------------------------------------ >> > > > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >> > > > >------------------------------------------ abez >> > > > >> > > > >> > > > _________________________________________________________________ >> > > > Add photos to your messages with MSN 8. Get 2 months FREE*. >> > > > http://join.msn.com/?page=features/featuredemail >> > > > >> > > >> > >-- >> > >abez ------------------------------------------ >> > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >> > >------------------------------------------ abez >> > >> > >> > _________________________________________________________________ >> > Help STOP SPAM with the new MSN 8 and get 2 months FREE* >> > http://join.msn.com/?page=features/junkmail >> > >> >>-- >>abez ------------------------------------------ >>http://www.abez.ca/ Abram Hindle (abez@abez.ca) >>------------------------------------------ abez > > >_________________________________________________________________ >Help STOP SPAM with the new MSN 8 and get 2 months FREE* >http://join.msn.com/?page=features/junkmail > -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From jeremygwa at hotmail.com Tue Feb 25 19:01:58 2003 From: jeremygwa at hotmail.com (Jeremy Aiyadurai) Date: Wed Aug 4 00:11:16 2004 Subject: Perl 5.8 threads and sockets problem Message-ID: Peter, Thanks for your reply. The script I am using is to test the use of sockets and threads or (forks). Basically, I would like to get this working so I can incorporate it into a program I am working on that will be a Win32 service (or unix Daemon) that checks many mail accounts for new messages at the same time, every few minutes or seconds. So that is the scoop. Your help "has been" and "is" greatly appreciated. Thanks, Jeremy A. >From: Peter Scott >To: Jeremy Aiyadurai , victoria-pm@pm.org >Subject: Re: Perl 5.8 threads and sockets problem >Date: Tue, 25 Feb 2003 16:37:21 -0800 > >I'm coming in a bit late here. I've no experience of Win32 programming >with threads or multiprocessing so this may not be much help. However, I >gather that the idea is to have something that keeps testing a POP3 >connection (I don't see any login to the accounts despite the fact that the >passwords are there). > >I don't see any use strict or use warnings, which is asking for trouble. >And there is no testing of the result of the open(), which is even worse. >Insufficient information without those. > >At 04:28 PM 2/25/03 -0800, Jeremy Aiyadurai wrote: > > > > >>Hi all, >> >>Thanks for all your help so far. >> >>I am still having having problems with the forking. >>the script will only run for 30 or so seconds, >>before it exits. >> >>I am stumped on how to keep it running continously. >> >>The following is the code >>............................................... >>use IO::Socket qw(:DEFAULT :crlf); >> >> >>my $pop3C; >>my @thr = (); >>my @Data = ( >> { 'UID' => "Jeremy", 'SVR' => "mail.h.y", 'PORT' => "110", >>'LOGIN' => "jerdoe", 'PASS' => "******" }, >> { 'UID' => "Jon", 'SVR' => "mail.h.t", 'PORT' => "110", >>'LOGIN' => "jondoe", 'PASS' => "****" }, >>); >>my $i = 0; >> >>Startup(); >> >> >>sub Startup { >> $| = 0; >> for (;;) { >> foreach my $account (@Data) { >> if (-f $account->{'UID'}.".acc") { >> next; >> } >> print "Forking $account->{UID}\n"; >> my $pid = fork(); >> if ($pid == 0){ >> # in child >> print "Child $account->{UID}\n"; >> go($account); >> $account = undef; >> exit(0); >> } >> >> } >> >> sleep(1); >> } >> } >> >> >> >>sub go() { >> my $ac = shift; >> >>$pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >> $ac->{SVR}, >> PeerPort => $ac->{PORT} , Timeout => 0) >> or pop3CError ($ac->{SVR},$ac->{PORT}); >>open(X,">".$ac->{UID}.".acc"); >>close(X); >>print "in $ac->{UID}\n"; >>$pop3C->close; >>unlink($ac->{'UID'}.".acc"); >>$ac->{'UID'} = undef; >>$ac->{'SVR'} = undef; >>$ac->{'PORT'} = undef; >>$ac->{'LOGIN'} = undef; >>$ac->{'PASS'} = undef; >>$pop3C = undef; >>} >> >>sub pop3CError ($$) { >> >>print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >>exit; >> >>} >>.................................................. >> >> >>Your help is much appreciated. >>Thanks, >> >>Jeremy A. >> >> >> >> >> >> >>>From: abez >>>To: Jeremy Aiyadurai >>>CC: victoria-pm@pm.org >>>Subject: Re: Perl 5.8 threads and sockets problem >>>Date: Sun, 23 Feb 2003 22:10:03 -0800 (PST) >>> >>> >>>Well uncomment these lines, so that you "locking" works. >>> > #if (-f $account->{'UID'}.".acc") { >>> > # next; >>> > #} >>> >>>I don't know WIN32 too well to guess about the memory but you might want >>>to >>>print before that exit where $account = undef; exit; Just print you're >>>closing >>>you might get better information. >>> >>>Also print debugging info to STDERR if possible it's default unbuffered. >>> >>>call wait() before you call sleep(1) and it will make sure your processes >>>aren't zombified. >>> >>> >>>On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >>> >>> > >>> > Hi again, >>> > >>> > Thanks for all your help so far. >>> > I monitored my memory usage while running the script. >>> > It appears to slowly eat up memory. If i were to run this script day >>>and >>> > night as long as I keep my computer on like a server, It would >>>probably >>> > crash my system even though I have alot of SDRAM. >>> > Also, the script will run for a while, then crash and exit, does this >>>have >>> > to do with fork (thread) races? >>> > eg. it ends like this >>> > " >>> > in Jeremy >>> > in Jon >>> > Forking Jeremy >>> > Forking Jon >>> > Child Jeremy >>> > Child Jon >>> > in Jeremy >>> > in Jon >>> > Forking Jeremy >>> > Child Jeremy >>> > in Jeremy" - exits here? don't know why? when three jeremy's are in >>> > sequence, the program terminates. >>> > >>> > Your Help is greatly appreciated >>> > >>> > Thanks, >>> > Jeremy A. >>> > >>> > here is the script now with the prints "Forking $UID","Child $UID" and >>>"in >>> > $UID". >>> > --------------------------- >>> > use IO::Socket qw(:DEFAULT :crlf); >>> > use Win32; >>> > >>> > >>> > my @thr = (); >>> > my @Data = ( >>> > { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => "110", >>> > 'LOGIN' => "jerdoe", 'PASS' => "********" }, >>> > { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", >>> > 'LOGIN' => "jondoe", 'PASS' => "*****" }, >>> > ); >>> > my $i = 0; >>> > >>> > Startup(); >>> > >>> > #foreach my $account (@Data) { >>> > # $str = " rm -f $account->{UID}.acc "; >>> > # `$str`; >>> > #} >>> > >>> > >>> > sub Startup { >>> > for (;;) { >>> > #Win32::Sleep(4000); >>> > $| = 0; >>> > foreach my $account (@Data) { >>> > #if (-f $account->{'UID'}.".acc") { >>> > # next; >>> > #} >>> > print "Forking $account->{UID}\n"; >>> > my $pid = fork(); >>> > if ($pid==0) { #child >>> > print "Child $account->{UID}\n"; >>> > go($account); >>> > $account = undef; >>> > exit(); >>> > } >>> > >>> > } >>> > sleep(1); >>> > } >>> > } >>> > >>> > >>> > >>> > >>> > sub go() { >>> > my $ac = shift; >>> > >>> > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >>> > $ac->{SVR}, >>> > PeerPort => $ac->{PORT} , Timeout => 0) >>> > or pop3CError ($ac->{SVR},$ac->{PORT}); >>> > open(X,">".$ac->{UID}.".acc"); >>> > close(X); >>> > print "in $ac->{UID}\n"; >>> > Win32::Sleep(4000); >>> > $pop3C->close; >>> > $ac->{'UID'} = undef; >>> > $ac->{'SVR'} = undef; >>> > $ac->{'PORT'} = undef; >>> > $ac->{'LOGIN'} = undef; >>> > $ac->{'PASS'} = undef; >>> > $pop3C = undef; >>> > unlink($_[1].".acc"); >>> > } >>> > >>> > sub pop3CError ($$) { >>> > >>> > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >>> > exit; >>> > >>> > } >>> > >>> > >>> > >>> > >>> > >From: abez >>> > >To: Jeremy Aiyadurai >>> > >CC: victoria-pm@pm.org >>> > >Subject: Re: Perl 5.8 threads and sockets problem >>> > >Date: Sun, 23 Feb 2003 20:35:24 -0800 (PST) >>> > > >>> > > >>> > > >>> > >Here's what I'd do: >>> > > >>> > >use IO::Socket qw(:DEFAULT :crlf); >>> > > >>> > >my @thr = (); >>> > >my @Data = ( >>> > > { 'UID' => "abez", 'SVR' => "lycos.com", 'PORT' => "80", >>> > >'LOGIN' => "abez", 'PASS' => "******" }, >>> > > { 'UID' => "casper", 'SVR' => "www.metafilter.com", 'PORT' => >>>"80", >>> > >'LOGIN' => "casper", 'PASS' => "*****" }, >>> > >); >>> > >my $i = 0; >>> > > >>> > >Startup(); >>> > > >>> > >foreach my $account (@Data) { >>> > > $str = " rm -f $account->{UID}.acc "; >>> > > `$str`; >>> > >} >>> > > >>> > >$| = 0; >>> > >sub Startup { >>> > > for (;;) { >>> > > #Win32::Sleep(4000); >>> > > foreach my $account (@Data) { >>> > > #if (-f $account->{'UID'}.".acc") { >>> > > # next; >>> > > #} >>> > > print "Forking $account->{UID}\n"; >>> > > my $pid = fork(); >>> > > if ($pid==0) { #child >>> > > print "Child $account->{UID}\n"; >>> > > go($account); >>> > > exit(); >>> > > } >>> > > } >>> > > sleep(10); >>> > > } >>> > > } >>> > > >>> > > >>> > > >>> > > >>> > >sub go($$$$$) { >>> > > my $account = shift; >>> > > >>> > >my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >>> > > $account->{SVR}, >>> > > PeerPort => $account->{PORT} , Timeout => 60) >>> > > or pop3CError ($account->{SVR},$account->{PORT}); >>> > >open(X,">".$account->{UID}.".acc"); >>> > >close(X); >>> > >print "in $account->{UID}\n"; >>> > >print $pop3C "GET /\n"; >>> > >my @out = <$pop3C>; >>> > >print join("",@out[0..10]),"\n"; >>> > >$pop3C->close; >>> > > >>> > >$pop3C = undef; >>> > >unlink($_[1].".acc"); >>> > >} >>> > > >>> > >sub pop3CError ($$) { >>> > > >>> > >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >>> > >exit; >>> > > >>> > >} >>> > > >>> > > >>> > > >>> > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >>> > > >>> > > > hi All, >>> > > > >>> > > > Thanks for your help so far. >>> > > > >>> > > > I tried threads->create, it made no difference, >>> > > > as mentioned in the manpage, "The new() method is an alias for >>>create(). >>> > >" >>> > > > >>> > > > Your Help is much appreciated, >>> > > > thanks >>> > > > >>> > > > Jeremy A. >>> > > > >>> > > > >From: abez >>> > > > >To: Jeremy Aiyadurai >>> > > > >CC: victoria-pm@pm.org >>> > > > >Subject: Re: Perl 5.8 threads and sockets problem >>> > > > >Date: Sun, 23 Feb 2003 18:38:16 -0800 (PST) >>> > > > > >>> > > > > >>> > > > >First of all try threads->create, rather than new. Other than >>>that I'm >>> > >too >>> > > > >dizzy to really help right now (flu). >>> > > > > >>> > > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >>> > > > > >>> > > > > > >>> > > > > > Hello all, >>> > > > > > >>> > > > > > I am new to the group. >>> > > > > > I have a problem involving sockets and threads. >>> > > > > > >>> > > > > > Basically, I want to be able to do two or more pop3 sessions >>> > > > >simultaniously >>> > > > > > using a list of different pop3 accounts. >>> > > > > > my problem is, I can logon to the first account, but when >>> > > > > > it comes to the second account's turn (in the second thread), >>>the >>> > >socket >>> > > > > > cannot be created. >>> > > > > > >>> > > > > > I am new to using threads and have little knowledge of >>>sockets. >>> > > > > > >>> > > > > > Your Help is much appreciated, >>> > > > > > >>> > > > > > Thanks, >>> > > > > > >>> > > > > > Jeremy A. >>> > > > > > >>> > > > > > Below is my test script I am having trouble with. >>> > > > > > >>> > > > > > >>> > > > > > #----------------------------------------------------- >>> > > > > > use threads; >>> > > > > > use Win32; >>> > > > > > use IO::Socket qw(:DEFAULT :crlf); >>> > > > > > >>> > > > > > >>> > > > > > my @thr; >>> > > > > > my @Data; >>> > > > > > $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", >>>'PORT' => >>> > > > >"110", >>> > > > > > 'LOGIN' => "account1", 'PASS' => "******" }; >>> > > > > > $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", 'PORT' >>>=> >>> > >"110", >>> > > > > > 'LOGIN' => "account2", 'PASS' => "*****" }; >>> > > > > > my $i = 0; >>> > > > > > >>> > > > > > sub Startup { >>> > > > > > while (1) { >>> > > > > > Win32::Sleep(4000); >>> > > > > > foreach my $account (@Data) >>> > > > > > { >>> > > > > > if(!open(T,"".$account->{'UID'}.".acc")) >>> > > > > > { >>> > > > > > Win32::Sleep(40); >>> > > > > > if($i != 0) >>> > > > > > { >>> > > > > > $i = $i + 1; >>> > > > > > } >>> > > > > > $thr[$i] = >>> > > > > > >>> > > > >>> > > >threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account-> >>>{'PORT'},$account->{'LOGIN'},$account->{'PASS'}); >>> > > > > > $thr[$i]->join; >>> > > > > > }else >>> > > > > > { >>> > > > > > close(T); >>> > > > > > } >>> > > > > > $i = $i - 1; >>> > > > > > >>> > > > > > } >>> > > > > > } >>> > > > > > @AC = -1; >>> > > > > > } >>> > > > > > >>> > > > > > Startup(); >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > sub go($$$$$) { >>> > > > > > print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n"; >>> > > > > > >>> > > > > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >>> > >"$_[1]", >>> > > > > > PeerPort => $_[2], Timeout => 60) or pop3CError ($_[1],$_[2]); >>> > > > > > open(X,">".$_[1].".acc"); >>> > > > > > close(X); >>> > > > > > print "in $_[1]\n"; >>> > > > > > sleep(1); >>> > > > > > pop3close($pop3C); >>> > > > > > $pop3C = undef; >>> > > > > > unlink($_[1].".acc"); >>> > > > > > } >>> > > > > > >>> > > > > > >>> > > > > > sub pop3CError ($$) { >>> > > > > > >>> > > > > > print "Cannot connect to the the Pop3 server:$_[0], >>>port:$_[1]\n"; >>> > > > > > exit; >>> > > > > > >>> > > > > > } >>> > > > > > >>> > > > > > >>> > > > > > sub pop3close ($) { >>> > > > > > if ($_[0]) { >>> > > > > > shutdown ($_[0], 2); >>> > > > > > } >>> > > > > > } >>> > > > > > #----------------------------------------------------- >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > >>>_________________________________________________________________ >>> > > > > > The new MSN 8: smart spam protection and 2 months FREE* >>> > > > > > http://join.msn.com/?page=features/junkmail >>> > > > > > >>> > > > > >>> > > > >-- >>> > > > >abez ------------------------------------------ >>> > > > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >>> > > > >------------------------------------------ abez >>> > > > >>> > > > >>> > > > _________________________________________________________________ >>> > > > Add photos to your messages with MSN 8. Get 2 months FREE*. >>> > > > http://join.msn.com/?page=features/featuredemail >>> > > > >>> > > >>> > >-- >>> > >abez ------------------------------------------ >>> > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >>> > >------------------------------------------ abez >>> > >>> > >>> > _________________________________________________________________ >>> > Help STOP SPAM with the new MSN 8 and get 2 months FREE* >>> > http://join.msn.com/?page=features/junkmail >>> > >>> >>>-- >>>abez ------------------------------------------ >>>http://www.abez.ca/ Abram Hindle (abez@abez.ca) >>>------------------------------------------ abez >> >> >>_________________________________________________________________ >>Help STOP SPAM with the new MSN 8 and get 2 months FREE* >>http://join.msn.com/?page=features/junkmail >> > >-- >Peter Scott >Pacific Systems Design Technologies >http://www.perldebugged.com/ > _________________________________________________________________ The new MSN 8: advanced junk mail protection and 2 months FREE* http://join.msn.com/?page=features/junkmail From Peter at PSDT.com Tue Feb 25 19:07:01 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:16 2004 Subject: Perl 5.8 threads and sockets problem In-Reply-To: Message-ID: <4.3.2.7.2.20030225170431.00ab1ab0@shell2.webquarry.com> At 05:01 PM 2/25/03 -0800, you wrote: >Peter, > >Thanks for your reply. The script I am using is to test the use of >sockets and threads or (forks). Basically, I would like to get this >working so I can incorporate it into a program I am working on that >will be a Win32 service (or unix Daemon) that checks many mail >accounts for new messages at the same time, every few minutes or seconds. Okay. Answer depends on how complicated you want to get. For maximum scalability I would use POE (Perl Object Environment) and their SocketFactory wheel if they haven't already written a POP3 wheel (see http://poe.perl.org). All the concurrency you want without either threads or forking. It will take a while to work through the learning curve but the resulting program will be more maintainable than anything else that could be as scalable. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From jeremygwa at hotmail.com Thu Feb 27 13:08:43 2003 From: jeremygwa at hotmail.com (Jeremy Aiyadurai) Date: Wed Aug 4 00:11:16 2004 Subject: Perl 5.8 threads and sockets problem Message-ID: Hi all, Thanks for all your help so far. Is there any easy way to do this. I've looked at POE (Perl Object Environment), but it is too confusing. The script I am using is to test the use of sockets and threads or (forks)(I prefer perl 5.8 threads over forks because of memory). Basically, I would like to get this working so I can incorporate it into a program I am working on that will be a Win32 service (or unix Daemon) that checks many mail (pop3) accounts for new messages at the same time, every few minutes or seconds. So that is the scoop. Your help "has been" and "is" greatly appreciated. Thanks, Jeremy A. The following script works for a couple seconds\minutes then exits (i dont know why) #---------------------------- use IO::Socket qw(:DEFAULT :crlf); use Strict; my $pop3C; my @thr = (); my @Data = ( { 'UID' => "Jeremy", 'SVR' => "mail.host.com", 'PORT' => "110", 'LOGIN' => "jerdoe", 'PASS' => "****" }, { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", 'LOGIN' => "jondoe", 'PASS' => "*******" }, ); my $i = 0; Startup(); sub Startup { $| = 0; for (;;) { foreach my $account (@Data) { if (-f $account->{'UID'}.".acc") { next; } print "Forking $account->{UID}\n"; #child my $pid = fork(); if ($pid == 0){ print "Child $account->{UID}\n"; go($account); $account = undef; exit(0); } } sleep(1); } } sub go() { my $ac = shift; open(X,">".$ac->{UID}.".acc"); $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => $ac->{SVR}, PeerPort => $ac->{PORT} , Timeout => 0) and close(X) or pop3CError ($ac->{SVR},$ac->{PORT}); print "in $ac->{UID}\n"; $pop3C->close; unlink($ac->{'UID'}.".acc"); $ac->{'UID'} = undef; $ac->{'SVR'} = undef; $ac->{'PORT'} = undef; $ac->{'LOGIN'} = undef; $ac->{'PASS'} = undef; $pop3C = undef; } sub pop3CError ($$) { close(X); print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; exit; } -------------------------------------- >From: "Jeremy Aiyadurai" >To: victoria-pm@pm.org >Subject: Re: Perl 5.8 threads and sockets problem >Date: Tue, 25 Feb 2003 16:28:55 -0800 >Hi all, > >Thanks for all your help so far. > >I am still having having problems with the forking. >the script will only run for 30 or so seconds, >before it exits. > >I am stumped on how to keep it running continously. > >The following is the code >............................................... >use IO::Socket qw(:DEFAULT :crlf); > > >my $pop3C; >my @thr = (); >my @Data = ( > { 'UID' => "Jeremy", 'SVR' => "mail.h.y", 'PORT' => "110", >'LOGIN' => "jerdoe", 'PASS' => "******" }, > { 'UID' => "Jon", 'SVR' => "mail.h.t", 'PORT' => "110", >'LOGIN' => "jondoe", 'PASS' => "****" }, >); >my $i = 0; > >Startup(); > > >sub Startup { > $| = 0; > for (;;) { > foreach my $account (@Data) { > if (-f $account->{'UID'}.".acc") { > next; > } > print "Forking $account->{UID}\n"; > my $pid = fork(); > if ($pid == 0){ > # in child > print "Child $account->{UID}\n"; > go($account); > $account = undef; > exit(0); > } > > } > > sleep(1); > } > } > > > >sub go() { > my $ac = shift; > >$pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > $ac->{SVR}, > PeerPort => $ac->{PORT} , Timeout => 0) > or pop3CError ($ac->{SVR},$ac->{PORT}); >open(X,">".$ac->{UID}.".acc"); >close(X); >print "in $ac->{UID}\n"; >$pop3C->close; >unlink($ac->{'UID'}.".acc"); >$ac->{'UID'} = undef; >$ac->{'SVR'} = undef; >$ac->{'PORT'} = undef; >$ac->{'LOGIN'} = undef; >$ac->{'PASS'} = undef; >$pop3C = undef; >} > >sub pop3CError ($$) { > >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >exit; > >} >.................................................. > > >Your help is much appreciated. >Thanks, > >Jeremy A. > > > > > > >>From: abez >>To: Jeremy Aiyadurai >>CC: victoria-pm@pm.org >>Subject: Re: Perl 5.8 threads and sockets problem >>Date: Sun, 23 Feb 2003 22:10:03 -0800 (PST) >> >> >>Well uncomment these lines, so that you "locking" works. >> > #if (-f $account->{'UID'}.".acc") { >> > # next; >> > #} >> >>I don't know WIN32 too well to guess about the memory but you might want >>to >>print before that exit where $account = undef; exit; Just print you're >>closing >>you might get better information. >> >>Also print debugging info to STDERR if possible it's default unbuffered. >> >>call wait() before you call sleep(1) and it will make sure your processes >>aren't zombified. >> >> >>On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >> >> > >> > Hi again, >> > >> > Thanks for all your help so far. >> > I monitored my memory usage while running the script. >> > It appears to slowly eat up memory. If i were to run this script day >>and >> > night as long as I keep my computer on like a server, It would probably >> > crash my system even though I have alot of SDRAM. >> > Also, the script will run for a while, then crash and exit, does this >>have >> > to do with fork (thread) races? >> > eg. it ends like this >> > " >> > in Jeremy >> > in Jon >> > Forking Jeremy >> > Forking Jon >> > Child Jeremy >> > Child Jon >> > in Jeremy >> > in Jon >> > Forking Jeremy >> > Child Jeremy >> > in Jeremy" - exits here? don't know why? when three jeremy's are in >> > sequence, the program terminates. >> > >> > Your Help is greatly appreciated >> > >> > Thanks, >> > Jeremy A. >> > >> > here is the script now with the prints "Forking $UID","Child $UID" and >>"in >> > $UID". >> > --------------------------- >> > use IO::Socket qw(:DEFAULT :crlf); >> > use Win32; >> > >> > >> > my @thr = (); >> > my @Data = ( >> > { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => "110", >> > 'LOGIN' => "jerdoe", 'PASS' => "********" }, >> > { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", >> > 'LOGIN' => "jondoe", 'PASS' => "*****" }, >> > ); >> > my $i = 0; >> > >> > Startup(); >> > >> > #foreach my $account (@Data) { >> > # $str = " rm -f $account->{UID}.acc "; >> > # `$str`; >> > #} >> > >> > >> > sub Startup { >> > for (;;) { >> > #Win32::Sleep(4000); >> > $| = 0; >> > foreach my $account (@Data) { >> > #if (-f $account->{'UID'}.".acc") { >> > # next; >> > #} >> > print "Forking $account->{UID}\n"; >> > my $pid = fork(); >> > if ($pid==0) { #child >> > print "Child $account->{UID}\n"; >> > go($account); >> > $account = undef; >> > exit(); >> > } >> > >> > } >> > sleep(1); >> > } >> > } >> > >> > >> > >> > >> > sub go() { >> > my $ac = shift; >> > >> > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >> > $ac->{SVR}, >> > PeerPort => $ac->{PORT} , Timeout => 0) >> > or pop3CError ($ac->{SVR},$ac->{PORT}); >> > open(X,">".$ac->{UID}.".acc"); >> > close(X); >> > print "in $ac->{UID}\n"; >> > Win32::Sleep(4000); >> > $pop3C->close; >> > $ac->{'UID'} = undef; >> > $ac->{'SVR'} = undef; >> > $ac->{'PORT'} = undef; >> > $ac->{'LOGIN'} = undef; >> > $ac->{'PASS'} = undef; >> > $pop3C = undef; >> > unlink($_[1].".acc"); >> > } >> > >> > sub pop3CError ($$) { >> > >> > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >> > exit; >> > >> > } >> > >> > >> > >> > >> > >From: abez >> > >To: Jeremy Aiyadurai >> > >CC: victoria-pm@pm.org >> > >Subject: Re: Perl 5.8 threads and sockets problem >> > >Date: Sun, 23 Feb 2003 20:35:24 -0800 (PST) >> > > >> > > >> > > >> > >Here's what I'd do: >> > > >> > >use IO::Socket qw(:DEFAULT :crlf); >> > > >> > >my @thr = (); >> > >my @Data = ( >> > > { 'UID' => "abez", 'SVR' => "lycos.com", 'PORT' => "80", >> > >'LOGIN' => "abez", 'PASS' => "******" }, >> > > { 'UID' => "casper", 'SVR' => "www.metafilter.com", 'PORT' => "80", >> > >'LOGIN' => "casper", 'PASS' => "*****" }, >> > >); >> > >my $i = 0; >> > > >> > >Startup(); >> > > >> > >foreach my $account (@Data) { >> > > $str = " rm -f $account->{UID}.acc "; >> > > `$str`; >> > >} >> > > >> > >$| = 0; >> > >sub Startup { >> > > for (;;) { >> > > #Win32::Sleep(4000); >> > > foreach my $account (@Data) { >> > > #if (-f $account->{'UID'}.".acc") { >> > > # next; >> > > #} >> > > print "Forking $account->{UID}\n"; >> > > my $pid = fork(); >> > > if ($pid==0) { #child >> > > print "Child $account->{UID}\n"; >> > > go($account); >> > > exit(); >> > > } >> > > } >> > > sleep(10); >> > > } >> > > } >> > > >> > > >> > > >> > > >> > >sub go($$$$$) { >> > > my $account = shift; >> > > >> > >my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >> > > $account->{SVR}, >> > > PeerPort => $account->{PORT} , Timeout => 60) >> > > or pop3CError ($account->{SVR},$account->{PORT}); >> > >open(X,">".$account->{UID}.".acc"); >> > >close(X); >> > >print "in $account->{UID}\n"; >> > >print $pop3C "GET /\n"; >> > >my @out = <$pop3C>; >> > >print join("",@out[0..10]),"\n"; >> > >$pop3C->close; >> > > >> > >$pop3C = undef; >> > >unlink($_[1].".acc"); >> > >} >> > > >> > >sub pop3CError ($$) { >> > > >> > >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >> > >exit; >> > > >> > >} >> > > >> > > >> > > >> > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >> > > >> > > > hi All, >> > > > >> > > > Thanks for your help so far. >> > > > >> > > > I tried threads->create, it made no difference, >> > > > as mentioned in the manpage, "The new() method is an alias for >>create(). >> > >" >> > > > >> > > > Your Help is much appreciated, >> > > > thanks >> > > > >> > > > Jeremy A. >> > > > >> > > > >From: abez >> > > > >To: Jeremy Aiyadurai >> > > > >CC: victoria-pm@pm.org >> > > > >Subject: Re: Perl 5.8 threads and sockets problem >> > > > >Date: Sun, 23 Feb 2003 18:38:16 -0800 (PST) >> > > > > >> > > > > >> > > > >First of all try threads->create, rather than new. Other than that >>I'm >> > >too >> > > > >dizzy to really help right now (flu). >> > > > > >> > > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >> > > > > >> > > > > > >> > > > > > Hello all, >> > > > > > >> > > > > > I am new to the group. >> > > > > > I have a problem involving sockets and threads. >> > > > > > >> > > > > > Basically, I want to be able to do two or more pop3 sessions >> > > > >simultaniously >> > > > > > using a list of different pop3 accounts. >> > > > > > my problem is, I can logon to the first account, but when >> > > > > > it comes to the second account's turn (in the second thread), >>the >> > >socket >> > > > > > cannot be created. >> > > > > > >> > > > > > I am new to using threads and have little knowledge of sockets. >> > > > > > >> > > > > > Your Help is much appreciated, >> > > > > > >> > > > > > Thanks, >> > > > > > >> > > > > > Jeremy A. >> > > > > > >> > > > > > Below is my test script I am having trouble with. >> > > > > > >> > > > > > >> > > > > > #----------------------------------------------------- >> > > > > > use threads; >> > > > > > use Win32; >> > > > > > use IO::Socket qw(:DEFAULT :crlf); >> > > > > > >> > > > > > >> > > > > > my @thr; >> > > > > > my @Data; >> > > > > > $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", >>'PORT' => >> > > > >"110", >> > > > > > 'LOGIN' => "account1", 'PASS' => "******" }; >> > > > > > $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", 'PORT' >>=> >> > >"110", >> > > > > > 'LOGIN' => "account2", 'PASS' => "*****" }; >> > > > > > my $i = 0; >> > > > > > >> > > > > > sub Startup { >> > > > > > while (1) { >> > > > > > Win32::Sleep(4000); >> > > > > > foreach my $account (@Data) >> > > > > > { >> > > > > > if(!open(T,"".$account->{'UID'}.".acc")) >> > > > > > { >> > > > > > Win32::Sleep(40); >> > > > > > if($i != 0) >> > > > > > { >> > > > > > $i = $i + 1; >> > > > > > } >> > > > > > $thr[$i] = >> > > > > > >> > > > >> > > >> >threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account->{'PORT'},$account->{'LOGIN'},$account->{'PASS'}); >> > > > > > $thr[$i]->join; >> > > > > > }else >> > > > > > { >> > > > > > close(T); >> > > > > > } >> > > > > > $i = $i - 1; >> > > > > > >> > > > > > } >> > > > > > } >> > > > > > @AC = -1; >> > > > > > } >> > > > > > >> > > > > > Startup(); >> > > > > > >> > > > > > >> > > > > > >> > > > > > sub go($$$$$) { >> > > > > > print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n"; >> > > > > > >> > > > > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >> > >"$_[1]", >> > > > > > PeerPort => $_[2], Timeout => 60) or pop3CError ($_[1],$_[2]); >> > > > > > open(X,">".$_[1].".acc"); >> > > > > > close(X); >> > > > > > print "in $_[1]\n"; >> > > > > > sleep(1); >> > > > > > pop3close($pop3C); >> > > > > > $pop3C = undef; >> > > > > > unlink($_[1].".acc"); >> > > > > > } >> > > > > > >> > > > > > >> > > > > > sub pop3CError ($$) { >> > > > > > >> > > > > > print "Cannot connect to the the Pop3 server:$_[0], >>port:$_[1]\n"; >> > > > > > exit; >> > > > > > >> > > > > > } >> > > > > > >> > > > > > >> > > > > > sub pop3close ($) { >> > > > > > if ($_[0]) { >> > > > > > shutdown ($_[0], 2); >> > > > > > } >> > > > > > } >> > > > > > #----------------------------------------------------- >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >> > > > > > >>_________________________________________________________________ >> > > > > > The new MSN 8: smart spam protection and 2 months FREE* >> > > > > > http://join.msn.com/?page=features/junkmail >> > > > > > >> > > > > >> > > > >-- >> > > > >abez ------------------------------------------ >> > > > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >> > > > >------------------------------------------ abez >> > > > >> > > > >> > > > _________________________________________________________________ >> > > > Add photos to your messages with MSN 8. Get 2 months FREE*. >> > > > http://join.msn.com/?page=features/featuredemail >> > > > >> > > >> > >-- >> > >abez ------------------------------------------ >> > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >> > >------------------------------------------ abez >> > >> > >> > _________________________________________________________________ >> > Help STOP SPAM with the new MSN 8 and get 2 months FREE* >> > http://join.msn.com/?page=features/junkmail >> > >> >>-- >>abez ------------------------------------------ >>http://www.abez.ca/ Abram Hindle (abez@abez.ca) >>------------------------------------------ abez > > >_________________________________________________________________ >Help STOP SPAM with the new MSN 8 and get 2 months FREE* >http://join.msn.com/?page=features/junkmail > _________________________________________________________________ Tired of spam? Get advanced junk mail protection with MSN 8. http://join.msn.com/?page=features/junkmail From nkuipers at uvic.ca Thu Feb 27 14:39:47 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:16 2004 Subject: Perl 5.8 threads and sockets problem Message-ID: <3E5E77C4@wm2.uvic.ca> >The following script works for a couple seconds\minutes then exits (i dont >know why) I really think the first thing you need to do is figure out why. Is the strict pragma called Strict in Win32 Perl? Also you should use warnings: use strict; use warnings; and then run perl -c yourscript You might try wrapping chunks of code in eval and seeing what happens too. What is the $i variable for? Why are you turning off the autoflush? What are you using the X filehandle for? You open it in go() and then ensure it is closed right away, in the next statement or failing that, as the first statement in the call to pop3CError(). I am not familiar with sockets at all, but I see no writing to the X filehandle anywhere... >#---------------------------- > >use IO::Socket qw(:DEFAULT :crlf); >use Strict; > > >my $pop3C; >my @thr = (); >my @Data = ( > { 'UID' => "Jeremy", 'SVR' => "mail.host.com", 'PORT' => "110", >'LOGIN' => "jerdoe", 'PASS' => "****" }, > { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", >'LOGIN' => "jondoe", 'PASS' => "*******" }, >); >my $i = 0; > >Startup(); > > > > >sub Startup { > $| = 0; > for (;;) { > foreach my $account (@Data) { > if (-f $account->{'UID'}.".acc") { > next; > } > print "Forking $account->{UID}\n"; > > #child > my $pid = fork(); > if ($pid == 0){ > print "Child $account->{UID}\n"; > go($account); > $account = undef; > exit(0); > } > > } > > sleep(1); > } > } > > > >sub go() { > my $ac = shift; >open(X,">".$ac->{UID}.".acc"); >$pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > $ac->{SVR}, > PeerPort => $ac->{PORT} , Timeout => 0) > and close(X) or pop3CError ($ac->{SVR},$ac->{PORT}); >print "in $ac->{UID}\n"; >$pop3C->close; >unlink($ac->{'UID'}.".acc"); >$ac->{'UID'} = undef; >$ac->{'SVR'} = undef; >$ac->{'PORT'} = undef; >$ac->{'LOGIN'} = undef; >$ac->{'PASS'} = undef; >$pop3C = undef; >} > >sub pop3CError ($$) { >close(X); >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >exit; > >} >-------------------------------------- >>From: "Jeremy Aiyadurai" >>To: victoria-pm@pm.org >>Subject: Re: Perl 5.8 threads and sockets problem >>Date: Tue, 25 Feb 2003 16:28:55 -0800 > >>Hi all, >> >>Thanks for all your help so far. >> >>I am still having having problems with the forking. >>the script will only run for 30 or so seconds, >>before it exits. >> >>I am stumped on how to keep it running continously. >> >>The following is the code >>............................................... >>use IO::Socket qw(:DEFAULT :crlf); >> >> >>my $pop3C; >>my @thr = (); >>my @Data = ( >> { 'UID' => "Jeremy", 'SVR' => "mail.h.y", 'PORT' => "110", >>'LOGIN' => "jerdoe", 'PASS' => "******" }, >> { 'UID' => "Jon", 'SVR' => "mail.h.t", 'PORT' => "110", >>'LOGIN' => "jondoe", 'PASS' => "****" }, >>); >>my $i = 0; >> >>Startup(); >> >> >>sub Startup { >> $| = 0; >> for (;;) { >> foreach my $account (@Data) { >> if (-f $account->{'UID'}.".acc") { >> next; >> } >> print "Forking $account->{UID}\n"; >> my $pid = fork(); >> if ($pid == 0){ >> # in child >> print "Child $account->{UID}\n"; >> go($account); >> $account = undef; >> exit(0); >> } >> >> } >> >> sleep(1); >> } >> } >> >> >> >>sub go() { >> my $ac = shift; >> >>$pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >> $ac->{SVR}, >> PeerPort => $ac->{PORT} , Timeout => 0) >> or pop3CError ($ac->{SVR},$ac->{PORT}); >>open(X,">".$ac->{UID}.".acc"); >>close(X); >>print "in $ac->{UID}\n"; >>$pop3C->close; >>unlink($ac->{'UID'}.".acc"); >>$ac->{'UID'} = undef; >>$ac->{'SVR'} = undef; >>$ac->{'PORT'} = undef; >>$ac->{'LOGIN'} = undef; >>$ac->{'PASS'} = undef; >>$pop3C = undef; >>} >> >>sub pop3CError ($$) { >> >>print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >>exit; >> >>} >>.................................................. >> >> >>Your help is much appreciated. >>Thanks, >> >>Jeremy A. >> >> >> >> >> >> >>>From: abez >>>To: Jeremy Aiyadurai >>>CC: victoria-pm@pm.org >>>Subject: Re: Perl 5.8 threads and sockets problem >>>Date: Sun, 23 Feb 2003 22:10:03 -0800 (PST) >>> >>> >>>Well uncomment these lines, so that you "locking" works. >>> > #if (-f $account->{'UID'}.".acc") { >>> > # next; >>> > #} >>> >>>I don't know WIN32 too well to guess about the memory but you might want >>>to >>>print before that exit where $account = undef; exit; Just print you're >>>closing >>>you might get better information. >>> >>>Also print debugging info to STDERR if possible it's default unbuffered. >>> >>>call wait() before you call sleep(1) and it will make sure your processes >>>aren't zombified. >>> >>> >>>On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >>> >>> > >>> > Hi again, >>> > >>> > Thanks for all your help so far. >>> > I monitored my memory usage while running the script. >>> > It appears to slowly eat up memory. If i were to run this script day >>>and >>> > night as long as I keep my computer on like a server, It would probably >>> > crash my system even though I have alot of SDRAM. >>> > Also, the script will run for a while, then crash and exit, does this >>>have >>> > to do with fork (thread) races? >>> > eg. it ends like this >>> > " >>> > in Jeremy >>> > in Jon >>> > Forking Jeremy >>> > Forking Jon >>> > Child Jeremy >>> > Child Jon >>> > in Jeremy >>> > in Jon >>> > Forking Jeremy >>> > Child Jeremy >>> > in Jeremy" - exits here? don't know why? when three jeremy's are in >>> > sequence, the program terminates. >>> > >>> > Your Help is greatly appreciated >>> > >>> > Thanks, >>> > Jeremy A. >>> > >>> > here is the script now with the prints "Forking $UID","Child $UID" and >>>"in >>> > $UID". >>> > --------------------------- >>> > use IO::Socket qw(:DEFAULT :crlf); >>> > use Win32; >>> > >>> > >>> > my @thr = (); >>> > my @Data = ( >>> > { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => "110", >>> > 'LOGIN' => "jerdoe", 'PASS' => "********" }, >>> > { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", >>> > 'LOGIN' => "jondoe", 'PASS' => "*****" }, >>> > ); >>> > my $i = 0; >>> > >>> > Startup(); >>> > >>> > #foreach my $account (@Data) { >>> > # $str = " rm -f $account->{UID}.acc "; >>> > # `$str`; >>> > #} >>> > >>> > >>> > sub Startup { >>> > for (;;) { >>> > #Win32::Sleep(4000); >>> > $| = 0; >>> > foreach my $account (@Data) { >>> > #if (-f $account->{'UID'}.".acc") { >>> > # next; >>> > #} >>> > print "Forking $account->{UID}\n"; >>> > my $pid = fork(); >>> > if ($pid==0) { #child >>> > print "Child $account->{UID}\n"; >>> > go($account); >>> > $account = undef; >>> > exit(); >>> > } >>> > >>> > } >>> > sleep(1); >>> > } >>> > } >>> > >>> > >>> > >>> > >>> > sub go() { >>> > my $ac = shift; >>> > >>> > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >>> > $ac->{SVR}, >>> > PeerPort => $ac->{PORT} , Timeout => 0) >>> > or pop3CError ($ac->{SVR},$ac->{PORT}); >>> > open(X,">".$ac->{UID}.".acc"); >>> > close(X); >>> > print "in $ac->{UID}\n"; >>> > Win32::Sleep(4000); >>> > $pop3C->close; >>> > $ac->{'UID'} = undef; >>> > $ac->{'SVR'} = undef; >>> > $ac->{'PORT'} = undef; >>> > $ac->{'LOGIN'} = undef; >>> > $ac->{'PASS'} = undef; >>> > $pop3C = undef; >>> > unlink($_[1].".acc"); >>> > } >>> > >>> > sub pop3CError ($$) { >>> > >>> > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >>> > exit; >>> > >>> > } >>> > >>> > >>> > >>> > >>> > >From: abez >>> > >To: Jeremy Aiyadurai >>> > >CC: victoria-pm@pm.org >>> > >Subject: Re: Perl 5.8 threads and sockets problem >>> > >Date: Sun, 23 Feb 2003 20:35:24 -0800 (PST) >>> > > >>> > > >>> > > >>> > >Here's what I'd do: >>> > > >>> > >use IO::Socket qw(:DEFAULT :crlf); >>> > > >>> > >my @thr = (); >>> > >my @Data = ( >>> > > { 'UID' => "abez", 'SVR' => "lycos.com", 'PORT' => "80", >>> > >'LOGIN' => "abez", 'PASS' => "******" }, >>> > > { 'UID' => "casper", 'SVR' => "www.metafilter.com", 'PORT' => "80", >>> > >'LOGIN' => "casper", 'PASS' => "*****" }, >>> > >); >>> > >my $i = 0; >>> > > >>> > >Startup(); >>> > > >>> > >foreach my $account (@Data) { >>> > > $str = " rm -f $account->{UID}.acc "; >>> > > `$str`; >>> > >} >>> > > >>> > >$| = 0; >>> > >sub Startup { >>> > > for (;;) { >>> > > #Win32::Sleep(4000); >>> > > foreach my $account (@Data) { >>> > > #if (-f $account->{'UID'}.".acc") { >>> > > # next; >>> > > #} >>> > > print "Forking $account->{UID}\n"; >>> > > my $pid = fork(); >>> > > if ($pid==0) { #child >>> > > print "Child $account->{UID}\n"; >>> > > go($account); >>> > > exit(); >>> > > } >>> > > } >>> > > sleep(10); >>> > > } >>> > > } >>> > > >>> > > >>> > > >>> > > >>> > >sub go($$$$$) { >>> > > my $account = shift; >>> > > >>> > >my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >>> > > $account->{SVR}, >>> > > PeerPort => $account->{PORT} , Timeout => 60) >>> > > or pop3CError ($account->{SVR},$account->{PORT}); >>> > >open(X,">".$account->{UID}.".acc"); >>> > >close(X); >>> > >print "in $account->{UID}\n"; >>> > >print $pop3C "GET /\n"; >>> > >my @out = <$pop3C>; >>> > >print join("",@out[0..10]),"\n"; >>> > >$pop3C->close; >>> > > >>> > >$pop3C = undef; >>> > >unlink($_[1].".acc"); >>> > >} >>> > > >>> > >sub pop3CError ($$) { >>> > > >>> > >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >>> > >exit; >>> > > >>> > >} >>> > > >>> > > >>> > > >>> > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >>> > > >>> > > > hi All, >>> > > > >>> > > > Thanks for your help so far. >>> > > > >>> > > > I tried threads->create, it made no difference, >>> > > > as mentioned in the manpage, "The new() method is an alias for >>>create(). >>> > >" >>> > > > >>> > > > Your Help is much appreciated, >>> > > > thanks >>> > > > >>> > > > Jeremy A. >>> > > > >>> > > > >From: abez >>> > > > >To: Jeremy Aiyadurai >>> > > > >CC: victoria-pm@pm.org >>> > > > >Subject: Re: Perl 5.8 threads and sockets problem >>> > > > >Date: Sun, 23 Feb 2003 18:38:16 -0800 (PST) >>> > > > > >>> > > > > >>> > > > >First of all try threads->create, rather than new. Other than that >>>I'm >>> > >too >>> > > > >dizzy to really help right now (flu). >>> > > > > >>> > > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >>> > > > > >>> > > > > > >>> > > > > > Hello all, >>> > > > > > >>> > > > > > I am new to the group. >>> > > > > > I have a problem involving sockets and threads. >>> > > > > > >>> > > > > > Basically, I want to be able to do two or more pop3 sessions >>> > > > >simultaniously >>> > > > > > using a list of different pop3 accounts. >>> > > > > > my problem is, I can logon to the first account, but when >>> > > > > > it comes to the second account's turn (in the second thread), >>>the >>> > >socket >>> > > > > > cannot be created. >>> > > > > > >>> > > > > > I am new to using threads and have little knowledge of sockets. >>> > > > > > >>> > > > > > Your Help is much appreciated, >>> > > > > > >>> > > > > > Thanks, >>> > > > > > >>> > > > > > Jeremy A. >>> > > > > > >>> > > > > > Below is my test script I am having trouble with. >>> > > > > > >>> > > > > > >>> > > > > > #----------------------------------------------------- >>> > > > > > use threads; >>> > > > > > use Win32; >>> > > > > > use IO::Socket qw(:DEFAULT :crlf); >>> > > > > > >>> > > > > > >>> > > > > > my @thr; >>> > > > > > my @Data; >>> > > > > > $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", >>>'PORT' => >>> > > > >"110", >>> > > > > > 'LOGIN' => "account1", 'PASS' => "******" }; >>> > > > > > $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", 'PORT' >>>=> >>> > >"110", >>> > > > > > 'LOGIN' => "account2", 'PASS' => "*****" }; >>> > > > > > my $i = 0; >>> > > > > > >>> > > > > > sub Startup { >>> > > > > > while (1) { >>> > > > > > Win32::Sleep(4000); >>> > > > > > foreach my $account (@Data) >>> > > > > > { >>> > > > > > if(!open(T,"".$account->{'UID'}.".acc")) >>> > > > > > { >>> > > > > > Win32::Sleep(40); >>> > > > > > if($i != 0) >>> > > > > > { >>> > > > > > $i = $i + 1; >>> > > > > > } >>> > > > > > $thr[$i] = >>> > > > > > >>> > > > >>> > > >>> >threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account->{'PORT'},$acc ount->{'LOGIN'},$account->{'PASS'}); >>> > > > > > $thr[$i]->join; >>> > > > > > }else >>> > > > > > { >>> > > > > > close(T); >>> > > > > > } >>> > > > > > $i = $i - 1; >>> > > > > > >>> > > > > > } >>> > > > > > } >>> > > > > > @AC = -1; >>> > > > > > } >>> > > > > > >>> > > > > > Startup(); >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > sub go($$$$$) { >>> > > > > > print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n"; >>> > > > > > >>> > > > > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >>> > >"$_[1]", >>> > > > > > PeerPort => $_[2], Timeout => 60) or pop3CError ($_[1],$_[2]); >>> > > > > > open(X,">".$_[1].".acc"); >>> > > > > > close(X); >>> > > > > > print "in $_[1]\n"; >>> > > > > > sleep(1); >>> > > > > > pop3close($pop3C); >>> > > > > > $pop3C = undef; >>> > > > > > unlink($_[1].".acc"); >>> > > > > > } >>> > > > > > >>> > > > > > >>> > > > > > sub pop3CError ($$) { >>> > > > > > >>> > > > > > print "Cannot connect to the the Pop3 server:$_[0], >>>port:$_[1]\n"; >>> > > > > > exit; >>> > > > > > >>> > > > > > } >>> > > > > > >>> > > > > > >>> > > > > > sub pop3close ($) { >>> > > > > > if ($_[0]) { >>> > > > > > shutdown ($_[0], 2); >>> > > > > > } >>> > > > > > } >>> > > > > > #----------------------------------------------------- >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > >>>_________________________________________________________________ >>> > > > > > The new MSN 8: smart spam protection and 2 months FREE* >>> > > > > > http://join.msn.com/?page=features/junkmail >>> > > > > > >>> > > > > >>> > > > >-- >>> > > > >abez ------------------------------------------ >>> > > > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >>> > > > >------------------------------------------ abez >>> > > > >>> > > > >>> > > > _________________________________________________________________ >>> > > > Add photos to your messages with MSN 8. Get 2 months FREE*. >>> > > > http://join.msn.com/?page=features/featuredemail >>> > > > >>> > > >>> > >-- >>> > >abez ------------------------------------------ >>> > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >>> > >------------------------------------------ abez >>> > >>> > >>> > _________________________________________________________________ >>> > Help STOP SPAM with the new MSN 8 and get 2 months FREE* >>> > http://join.msn.com/?page=features/junkmail >>> > >>> >>>-- >>>abez ------------------------------------------ >>>http://www.abez.ca/ Abram Hindle (abez@abez.ca) >>>------------------------------------------ abez >> >> >>_________________________________________________________________ >>Help STOP SPAM with the new MSN 8 and get 2 months FREE* >>http://join.msn.com/?page=features/junkmail >> > > >_________________________________________________________________ >Tired of spam? Get advanced junk mail protection with MSN 8. >http://join.msn.com/?page=features/junkmail From nkuipers at uvic.ca Thu Feb 27 14:53:34 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:16 2004 Subject: Perl 5.8 threads and sockets problem Message-ID: <3E5E830C@wm2.uvic.ca> One more thing. Print $pid every iteration, and clean up the $pop3C definition line. What I mean is there are two hardcoded reasons for exiting, one if $pid is zero and the other at the $pop3C definition, which uses and/or in the same line, which is not common...I'm not saying it's a problem line per se, I'm just saying you don't often see and/or used together and it IS a line that could jump to a "premature" exit, so it is worth some cleaning up and attention. >===== Original Message From "Jeremy Aiyadurai" ===== >Hi all, >Thanks for all your help so far. Is there any easy way to do this. >I've looked at POE (Perl Object Environment), but it is too confusing. > >The script I am using is to test the use of sockets and threads or (forks)(I >prefer perl 5.8 threads over forks because of memory). Basically, I would >like to get this working so I can incorporate it into a program I am working >on that will be a Win32 service (or unix Daemon) that checks many mail >(pop3) accounts for new messages at the same time, every few minutes or >seconds. > >So that is the scoop. > >Your help "has been" and "is" greatly appreciated. >Thanks, > >Jeremy A. > >The following script works for a couple seconds\minutes then exits (i dont >know why) >#---------------------------- > >use IO::Socket qw(:DEFAULT :crlf); >use Strict; > > >my $pop3C; >my @thr = (); >my @Data = ( > { 'UID' => "Jeremy", 'SVR' => "mail.host.com", 'PORT' => "110", >'LOGIN' => "jerdoe", 'PASS' => "****" }, > { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", >'LOGIN' => "jondoe", 'PASS' => "*******" }, >); >my $i = 0; > >Startup(); > > > > >sub Startup { > $| = 0; > for (;;) { > foreach my $account (@Data) { > if (-f $account->{'UID'}.".acc") { > next; > } > print "Forking $account->{UID}\n"; > > #child > my $pid = fork(); > if ($pid == 0){ > print "Child $account->{UID}\n"; > go($account); > $account = undef; > exit(0); > } > > } > > sleep(1); > } > } > > > >sub go() { > my $ac = shift; >open(X,">".$ac->{UID}.".acc"); >$pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > $ac->{SVR}, > PeerPort => $ac->{PORT} , Timeout => 0) > and close(X) or pop3CError ($ac->{SVR},$ac->{PORT}); >print "in $ac->{UID}\n"; >$pop3C->close; >unlink($ac->{'UID'}.".acc"); >$ac->{'UID'} = undef; >$ac->{'SVR'} = undef; >$ac->{'PORT'} = undef; >$ac->{'LOGIN'} = undef; >$ac->{'PASS'} = undef; >$pop3C = undef; >} > >sub pop3CError ($$) { >close(X); >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >exit; > >} >-------------------------------------- >>From: "Jeremy Aiyadurai" >>To: victoria-pm@pm.org >>Subject: Re: Perl 5.8 threads and sockets problem >>Date: Tue, 25 Feb 2003 16:28:55 -0800 > >>Hi all, >> >>Thanks for all your help so far. >> >>I am still having having problems with the forking. >>the script will only run for 30 or so seconds, >>before it exits. >> >>I am stumped on how to keep it running continously. >> >>The following is the code >>............................................... >>use IO::Socket qw(:DEFAULT :crlf); >> >> >>my $pop3C; >>my @thr = (); >>my @Data = ( >> { 'UID' => "Jeremy", 'SVR' => "mail.h.y", 'PORT' => "110", >>'LOGIN' => "jerdoe", 'PASS' => "******" }, >> { 'UID' => "Jon", 'SVR' => "mail.h.t", 'PORT' => "110", >>'LOGIN' => "jondoe", 'PASS' => "****" }, >>); >>my $i = 0; >> >>Startup(); >> >> >>sub Startup { >> $| = 0; >> for (;;) { >> foreach my $account (@Data) { >> if (-f $account->{'UID'}.".acc") { >> next; >> } >> print "Forking $account->{UID}\n"; >> my $pid = fork(); >> if ($pid == 0){ >> # in child >> print "Child $account->{UID}\n"; >> go($account); >> $account = undef; >> exit(0); >> } >> >> } >> >> sleep(1); >> } >> } >> >> >> >>sub go() { >> my $ac = shift; >> >>$pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >> $ac->{SVR}, >> PeerPort => $ac->{PORT} , Timeout => 0) >> or pop3CError ($ac->{SVR},$ac->{PORT}); >>open(X,">".$ac->{UID}.".acc"); >>close(X); >>print "in $ac->{UID}\n"; >>$pop3C->close; >>unlink($ac->{'UID'}.".acc"); >>$ac->{'UID'} = undef; >>$ac->{'SVR'} = undef; >>$ac->{'PORT'} = undef; >>$ac->{'LOGIN'} = undef; >>$ac->{'PASS'} = undef; >>$pop3C = undef; >>} >> >>sub pop3CError ($$) { >> >>print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >>exit; >> >>} >>.................................................. >> >> >>Your help is much appreciated. >>Thanks, >> >>Jeremy A. >> >> >> >> >> >> >>>From: abez >>>To: Jeremy Aiyadurai >>>CC: victoria-pm@pm.org >>>Subject: Re: Perl 5.8 threads and sockets problem >>>Date: Sun, 23 Feb 2003 22:10:03 -0800 (PST) >>> >>> >>>Well uncomment these lines, so that you "locking" works. >>> > #if (-f $account->{'UID'}.".acc") { >>> > # next; >>> > #} >>> >>>I don't know WIN32 too well to guess about the memory but you might want >>>to >>>print before that exit where $account = undef; exit; Just print you're >>>closing >>>you might get better information. >>> >>>Also print debugging info to STDERR if possible it's default unbuffered. >>> >>>call wait() before you call sleep(1) and it will make sure your processes >>>aren't zombified. >>> >>> >>>On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >>> >>> > >>> > Hi again, >>> > >>> > Thanks for all your help so far. >>> > I monitored my memory usage while running the script. >>> > It appears to slowly eat up memory. If i were to run this script day >>>and >>> > night as long as I keep my computer on like a server, It would probably >>> > crash my system even though I have alot of SDRAM. >>> > Also, the script will run for a while, then crash and exit, does this >>>have >>> > to do with fork (thread) races? >>> > eg. it ends like this >>> > " >>> > in Jeremy >>> > in Jon >>> > Forking Jeremy >>> > Forking Jon >>> > Child Jeremy >>> > Child Jon >>> > in Jeremy >>> > in Jon >>> > Forking Jeremy >>> > Child Jeremy >>> > in Jeremy" - exits here? don't know why? when three jeremy's are in >>> > sequence, the program terminates. >>> > >>> > Your Help is greatly appreciated >>> > >>> > Thanks, >>> > Jeremy A. >>> > >>> > here is the script now with the prints "Forking $UID","Child $UID" and >>>"in >>> > $UID". >>> > --------------------------- >>> > use IO::Socket qw(:DEFAULT :crlf); >>> > use Win32; >>> > >>> > >>> > my @thr = (); >>> > my @Data = ( >>> > { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => "110", >>> > 'LOGIN' => "jerdoe", 'PASS' => "********" }, >>> > { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", >>> > 'LOGIN' => "jondoe", 'PASS' => "*****" }, >>> > ); >>> > my $i = 0; >>> > >>> > Startup(); >>> > >>> > #foreach my $account (@Data) { >>> > # $str = " rm -f $account->{UID}.acc "; >>> > # `$str`; >>> > #} >>> > >>> > >>> > sub Startup { >>> > for (;;) { >>> > #Win32::Sleep(4000); >>> > $| = 0; >>> > foreach my $account (@Data) { >>> > #if (-f $account->{'UID'}.".acc") { >>> > # next; >>> > #} >>> > print "Forking $account->{UID}\n"; >>> > my $pid = fork(); >>> > if ($pid==0) { #child >>> > print "Child $account->{UID}\n"; >>> > go($account); >>> > $account = undef; >>> > exit(); >>> > } >>> > >>> > } >>> > sleep(1); >>> > } >>> > } >>> > >>> > >>> > >>> > >>> > sub go() { >>> > my $ac = shift; >>> > >>> > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >>> > $ac->{SVR}, >>> > PeerPort => $ac->{PORT} , Timeout => 0) >>> > or pop3CError ($ac->{SVR},$ac->{PORT}); >>> > open(X,">".$ac->{UID}.".acc"); >>> > close(X); >>> > print "in $ac->{UID}\n"; >>> > Win32::Sleep(4000); >>> > $pop3C->close; >>> > $ac->{'UID'} = undef; >>> > $ac->{'SVR'} = undef; >>> > $ac->{'PORT'} = undef; >>> > $ac->{'LOGIN'} = undef; >>> > $ac->{'PASS'} = undef; >>> > $pop3C = undef; >>> > unlink($_[1].".acc"); >>> > } >>> > >>> > sub pop3CError ($$) { >>> > >>> > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >>> > exit; >>> > >>> > } >>> > >>> > >>> > >>> > >>> > >From: abez >>> > >To: Jeremy Aiyadurai >>> > >CC: victoria-pm@pm.org >>> > >Subject: Re: Perl 5.8 threads and sockets problem >>> > >Date: Sun, 23 Feb 2003 20:35:24 -0800 (PST) >>> > > >>> > > >>> > > >>> > >Here's what I'd do: >>> > > >>> > >use IO::Socket qw(:DEFAULT :crlf); >>> > > >>> > >my @thr = (); >>> > >my @Data = ( >>> > > { 'UID' => "abez", 'SVR' => "lycos.com", 'PORT' => "80", >>> > >'LOGIN' => "abez", 'PASS' => "******" }, >>> > > { 'UID' => "casper", 'SVR' => "www.metafilter.com", 'PORT' => "80", >>> > >'LOGIN' => "casper", 'PASS' => "*****" }, >>> > >); >>> > >my $i = 0; >>> > > >>> > >Startup(); >>> > > >>> > >foreach my $account (@Data) { >>> > > $str = " rm -f $account->{UID}.acc "; >>> > > `$str`; >>> > >} >>> > > >>> > >$| = 0; >>> > >sub Startup { >>> > > for (;;) { >>> > > #Win32::Sleep(4000); >>> > > foreach my $account (@Data) { >>> > > #if (-f $account->{'UID'}.".acc") { >>> > > # next; >>> > > #} >>> > > print "Forking $account->{UID}\n"; >>> > > my $pid = fork(); >>> > > if ($pid==0) { #child >>> > > print "Child $account->{UID}\n"; >>> > > go($account); >>> > > exit(); >>> > > } >>> > > } >>> > > sleep(10); >>> > > } >>> > > } >>> > > >>> > > >>> > > >>> > > >>> > >sub go($$$$$) { >>> > > my $account = shift; >>> > > >>> > >my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >>> > > $account->{SVR}, >>> > > PeerPort => $account->{PORT} , Timeout => 60) >>> > > or pop3CError ($account->{SVR},$account->{PORT}); >>> > >open(X,">".$account->{UID}.".acc"); >>> > >close(X); >>> > >print "in $account->{UID}\n"; >>> > >print $pop3C "GET /\n"; >>> > >my @out = <$pop3C>; >>> > >print join("",@out[0..10]),"\n"; >>> > >$pop3C->close; >>> > > >>> > >$pop3C = undef; >>> > >unlink($_[1].".acc"); >>> > >} >>> > > >>> > >sub pop3CError ($$) { >>> > > >>> > >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >>> > >exit; >>> > > >>> > >} >>> > > >>> > > >>> > > >>> > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >>> > > >>> > > > hi All, >>> > > > >>> > > > Thanks for your help so far. >>> > > > >>> > > > I tried threads->create, it made no difference, >>> > > > as mentioned in the manpage, "The new() method is an alias for >>>create(). >>> > >" >>> > > > >>> > > > Your Help is much appreciated, >>> > > > thanks >>> > > > >>> > > > Jeremy A. >>> > > > >>> > > > >From: abez >>> > > > >To: Jeremy Aiyadurai >>> > > > >CC: victoria-pm@pm.org >>> > > > >Subject: Re: Perl 5.8 threads and sockets problem >>> > > > >Date: Sun, 23 Feb 2003 18:38:16 -0800 (PST) >>> > > > > >>> > > > > >>> > > > >First of all try threads->create, rather than new. Other than that >>>I'm >>> > >too >>> > > > >dizzy to really help right now (flu). >>> > > > > >>> > > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >>> > > > > >>> > > > > > >>> > > > > > Hello all, >>> > > > > > >>> > > > > > I am new to the group. >>> > > > > > I have a problem involving sockets and threads. >>> > > > > > >>> > > > > > Basically, I want to be able to do two or more pop3 sessions >>> > > > >simultaniously >>> > > > > > using a list of different pop3 accounts. >>> > > > > > my problem is, I can logon to the first account, but when >>> > > > > > it comes to the second account's turn (in the second thread), >>>the >>> > >socket >>> > > > > > cannot be created. >>> > > > > > >>> > > > > > I am new to using threads and have little knowledge of sockets. >>> > > > > > >>> > > > > > Your Help is much appreciated, >>> > > > > > >>> > > > > > Thanks, >>> > > > > > >>> > > > > > Jeremy A. >>> > > > > > >>> > > > > > Below is my test script I am having trouble with. >>> > > > > > >>> > > > > > >>> > > > > > #----------------------------------------------------- >>> > > > > > use threads; >>> > > > > > use Win32; >>> > > > > > use IO::Socket qw(:DEFAULT :crlf); >>> > > > > > >>> > > > > > >>> > > > > > my @thr; >>> > > > > > my @Data; >>> > > > > > $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", >>>'PORT' => >>> > > > >"110", >>> > > > > > 'LOGIN' => "account1", 'PASS' => "******" }; >>> > > > > > $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", 'PORT' >>>=> >>> > >"110", >>> > > > > > 'LOGIN' => "account2", 'PASS' => "*****" }; >>> > > > > > my $i = 0; >>> > > > > > >>> > > > > > sub Startup { >>> > > > > > while (1) { >>> > > > > > Win32::Sleep(4000); >>> > > > > > foreach my $account (@Data) >>> > > > > > { >>> > > > > > if(!open(T,"".$account->{'UID'}.".acc")) >>> > > > > > { >>> > > > > > Win32::Sleep(40); >>> > > > > > if($i != 0) >>> > > > > > { >>> > > > > > $i = $i + 1; >>> > > > > > } >>> > > > > > $thr[$i] = >>> > > > > > >>> > > > >>> > > >>> >threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account->{'PORT'},$acc ount->{'LOGIN'},$account->{'PASS'}); >>> > > > > > $thr[$i]->join; >>> > > > > > }else >>> > > > > > { >>> > > > > > close(T); >>> > > > > > } >>> > > > > > $i = $i - 1; >>> > > > > > >>> > > > > > } >>> > > > > > } >>> > > > > > @AC = -1; >>> > > > > > } >>> > > > > > >>> > > > > > Startup(); >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > sub go($$$$$) { >>> > > > > > print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n"; >>> > > > > > >>> > > > > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >>> > >"$_[1]", >>> > > > > > PeerPort => $_[2], Timeout => 60) or pop3CError ($_[1],$_[2]); >>> > > > > > open(X,">".$_[1].".acc"); >>> > > > > > close(X); >>> > > > > > print "in $_[1]\n"; >>> > > > > > sleep(1); >>> > > > > > pop3close($pop3C); >>> > > > > > $pop3C = undef; >>> > > > > > unlink($_[1].".acc"); >>> > > > > > } >>> > > > > > >>> > > > > > >>> > > > > > sub pop3CError ($$) { >>> > > > > > >>> > > > > > print "Cannot connect to the the Pop3 server:$_[0], >>>port:$_[1]\n"; >>> > > > > > exit; >>> > > > > > >>> > > > > > } >>> > > > > > >>> > > > > > >>> > > > > > sub pop3close ($) { >>> > > > > > if ($_[0]) { >>> > > > > > shutdown ($_[0], 2); >>> > > > > > } >>> > > > > > } >>> > > > > > #----------------------------------------------------- >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > >>> > > > > > >>>_________________________________________________________________ >>> > > > > > The new MSN 8: smart spam protection and 2 months FREE* >>> > > > > > http://join.msn.com/?page=features/junkmail >>> > > > > > >>> > > > > >>> > > > >-- >>> > > > >abez ------------------------------------------ >>> > > > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >>> > > > >------------------------------------------ abez >>> > > > >>> > > > >>> > > > _________________________________________________________________ >>> > > > Add photos to your messages with MSN 8. Get 2 months FREE*. >>> > > > http://join.msn.com/?page=features/featuredemail >>> > > > >>> > > >>> > >-- >>> > >abez ------------------------------------------ >>> > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >>> > >------------------------------------------ abez >>> > >>> > >>> > _________________________________________________________________ >>> > Help STOP SPAM with the new MSN 8 and get 2 months FREE* >>> > http://join.msn.com/?page=features/junkmail >>> > >>> >>>-- >>>abez ------------------------------------------ >>>http://www.abez.ca/ Abram Hindle (abez@abez.ca) >>>------------------------------------------ abez >> >> >>_________________________________________________________________ >>Help STOP SPAM with the new MSN 8 and get 2 months FREE* >>http://join.msn.com/?page=features/junkmail >> > > >_________________________________________________________________ >Tired of spam? Get advanced junk mail protection with MSN 8. >http://join.msn.com/?page=features/junkmail From jeremygwa at hotmail.com Thu Feb 27 14:55:28 2003 From: jeremygwa at hotmail.com (Jeremy Aiyadurai) Date: Wed Aug 4 00:11:17 2004 Subject: Perl 5.8 threads and sockets problem Message-ID: Thanks for the advice. I added the "strict" and "warnings". i also did perl -c *.pl. I get this output just before the script exits: "... Forking Jon Child Jeremy Child Jon in Jeremy in Jon Forking Jeremy Use of uninitialized value in numeric eq (==) at E:\backup\perlstuff\project\mai lclient\Emia4Win\Emia4Win-EmiaSVC2003.02.24perlapp-selectslice\pig2.pl line 33. Child Jeremy in Jeremy" Your help is greatly and always appreciated. Thanks, Jeremy A. >From: nkuipers >To: "Jeremy Aiyadurai" >CC: victoria-pm@pm.org >Subject: RE: Perl 5.8 threads and sockets problem >Date: Thu, 27 Feb 2003 12:39:47 -0800 > > >The following script works for a couple seconds\minutes then exits (i >dont > >know why) > >I really think the first thing you need to do is figure out why. Is the >strict pragma called Strict in Win32 Perl? Also you should use warnings: > >use strict; >use warnings; > >and then run > >perl -c yourscript > >You might try wrapping chunks of code in eval and seeing what happens too. > >What is the $i variable for? Why are you turning off the autoflush? What >are >you using the X filehandle for? You open it in go() and then ensure it is >closed right away, in the next statement or failing that, as the first >statement in the call to pop3CError(). I am not familiar with sockets at >all, >but I see no writing to the X filehandle anywhere... > > > > >#---------------------------- > > > >use IO::Socket qw(:DEFAULT :crlf); > >use Strict; > > > > > >my $pop3C; > >my @thr = (); > >my @Data = ( > > { 'UID' => "Jeremy", 'SVR' => "mail.host.com", 'PORT' => "110", > >'LOGIN' => "jerdoe", 'PASS' => "****" }, > > { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", > >'LOGIN' => "jondoe", 'PASS' => "*******" }, > >); > >my $i = 0; > > > >Startup(); > > > > > > > > > >sub Startup { > > $| = 0; > > for (;;) { > > foreach my $account (@Data) { > > if (-f $account->{'UID'}.".acc") { > > next; > > } > > print "Forking $account->{UID}\n"; > > > > #child > > my $pid = fork(); > > if ($pid == 0){ > > print "Child $account->{UID}\n"; > > go($account); > > $account = undef; > > exit(0); > > } > > > > } > > > > sleep(1); > > } > > } > > > > > > > >sub go() { > > my $ac = shift; > >open(X,">".$ac->{UID}.".acc"); > >$pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > > $ac->{SVR}, > > PeerPort => $ac->{PORT} , Timeout => 0) > > and close(X) or pop3CError ($ac->{SVR},$ac->{PORT}); > >print "in $ac->{UID}\n"; > >$pop3C->close; > >unlink($ac->{'UID'}.".acc"); > >$ac->{'UID'} = undef; > >$ac->{'SVR'} = undef; > >$ac->{'PORT'} = undef; > >$ac->{'LOGIN'} = undef; > >$ac->{'PASS'} = undef; > >$pop3C = undef; > >} > > > >sub pop3CError ($$) { > >close(X); > >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; > >exit; > > > >} > >-------------------------------------- > >>From: "Jeremy Aiyadurai" > >>To: victoria-pm@pm.org > >>Subject: Re: Perl 5.8 threads and sockets problem > >>Date: Tue, 25 Feb 2003 16:28:55 -0800 > > > >>Hi all, > >> > >>Thanks for all your help so far. > >> > >>I am still having having problems with the forking. > >>the script will only run for 30 or so seconds, > >>before it exits. > >> > >>I am stumped on how to keep it running continously. > >> > >>The following is the code > >>............................................... > >>use IO::Socket qw(:DEFAULT :crlf); > >> > >> > >>my $pop3C; > >>my @thr = (); > >>my @Data = ( > >> { 'UID' => "Jeremy", 'SVR' => "mail.h.y", 'PORT' => "110", > >>'LOGIN' => "jerdoe", 'PASS' => "******" }, > >> { 'UID' => "Jon", 'SVR' => "mail.h.t", 'PORT' => "110", > >>'LOGIN' => "jondoe", 'PASS' => "****" }, > >>); > >>my $i = 0; > >> > >>Startup(); > >> > >> > >>sub Startup { > >> $| = 0; > >> for (;;) { > >> foreach my $account (@Data) { > >> if (-f $account->{'UID'}.".acc") { > >> next; > >> } > >> print "Forking $account->{UID}\n"; > >> my $pid = fork(); > >> if ($pid == 0){ > >> # in child > >> print "Child $account->{UID}\n"; > >> go($account); > >> $account = undef; > >> exit(0); > >> } > >> > >> } > >> > >> sleep(1); > >> } > >> } > >> > >> > >> > >>sub go() { > >> my $ac = shift; > >> > >>$pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > >> $ac->{SVR}, > >> PeerPort => $ac->{PORT} , Timeout => 0) > >> or pop3CError ($ac->{SVR},$ac->{PORT}); > >>open(X,">".$ac->{UID}.".acc"); > >>close(X); > >>print "in $ac->{UID}\n"; > >>$pop3C->close; > >>unlink($ac->{'UID'}.".acc"); > >>$ac->{'UID'} = undef; > >>$ac->{'SVR'} = undef; > >>$ac->{'PORT'} = undef; > >>$ac->{'LOGIN'} = undef; > >>$ac->{'PASS'} = undef; > >>$pop3C = undef; > >>} > >> > >>sub pop3CError ($$) { > >> > >>print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; > >>exit; > >> > >>} > >>.................................................. > >> > >> > >>Your help is much appreciated. > >>Thanks, > >> > >>Jeremy A. > >> > >> > >> > >> > >> > >> > >>>From: abez > >>>To: Jeremy Aiyadurai > >>>CC: victoria-pm@pm.org > >>>Subject: Re: Perl 5.8 threads and sockets problem > >>>Date: Sun, 23 Feb 2003 22:10:03 -0800 (PST) > >>> > >>> > >>>Well uncomment these lines, so that you "locking" works. > >>> > #if (-f $account->{'UID'}.".acc") { > >>> > # next; > >>> > #} > >>> > >>>I don't know WIN32 too well to guess about the memory but you might >want > >>>to > >>>print before that exit where $account = undef; exit; Just print you're > >>>closing > >>>you might get better information. > >>> > >>>Also print debugging info to STDERR if possible it's default >unbuffered. > >>> > >>>call wait() before you call sleep(1) and it will make sure your >processes > >>>aren't zombified. > >>> > >>> > >>>On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > >>> > >>> > > >>> > Hi again, > >>> > > >>> > Thanks for all your help so far. > >>> > I monitored my memory usage while running the script. > >>> > It appears to slowly eat up memory. If i were to run this script day > >>>and > >>> > night as long as I keep my computer on like a server, It would >probably > >>> > crash my system even though I have alot of SDRAM. > >>> > Also, the script will run for a while, then crash and exit, does >this > >>>have > >>> > to do with fork (thread) races? > >>> > eg. it ends like this > >>> > " > >>> > in Jeremy > >>> > in Jon > >>> > Forking Jeremy > >>> > Forking Jon > >>> > Child Jeremy > >>> > Child Jon > >>> > in Jeremy > >>> > in Jon > >>> > Forking Jeremy > >>> > Child Jeremy > >>> > in Jeremy" - exits here? don't know why? when three jeremy's are in > >>> > sequence, the program terminates. > >>> > > >>> > Your Help is greatly appreciated > >>> > > >>> > Thanks, > >>> > Jeremy A. > >>> > > >>> > here is the script now with the prints "Forking $UID","Child $UID" >and > >>>"in > >>> > $UID". > >>> > --------------------------- > >>> > use IO::Socket qw(:DEFAULT :crlf); > >>> > use Win32; > >>> > > >>> > > >>> > my @thr = (); > >>> > my @Data = ( > >>> > { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => "110", > >>> > 'LOGIN' => "jerdoe", 'PASS' => "********" }, > >>> > { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", > >>> > 'LOGIN' => "jondoe", 'PASS' => "*****" }, > >>> > ); > >>> > my $i = 0; > >>> > > >>> > Startup(); > >>> > > >>> > #foreach my $account (@Data) { > >>> > # $str = " rm -f $account->{UID}.acc "; > >>> > # `$str`; > >>> > #} > >>> > > >>> > > >>> > sub Startup { > >>> > for (;;) { > >>> > #Win32::Sleep(4000); > >>> > $| = 0; > >>> > foreach my $account (@Data) { > >>> > #if (-f $account->{'UID'}.".acc") { > >>> > # next; > >>> > #} > >>> > print "Forking $account->{UID}\n"; > >>> > my $pid = fork(); > >>> > if ($pid==0) { #child > >>> > print "Child $account->{UID}\n"; > >>> > go($account); > >>> > $account = undef; > >>> > exit(); > >>> > } > >>> > > >>> > } > >>> > sleep(1); > >>> > } > >>> > } > >>> > > >>> > > >>> > > >>> > > >>> > sub go() { > >>> > my $ac = shift; > >>> > > >>> > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > >>> > $ac->{SVR}, > >>> > PeerPort => $ac->{PORT} , Timeout => 0) > >>> > or pop3CError ($ac->{SVR},$ac->{PORT}); > >>> > open(X,">".$ac->{UID}.".acc"); > >>> > close(X); > >>> > print "in $ac->{UID}\n"; > >>> > Win32::Sleep(4000); > >>> > $pop3C->close; > >>> > $ac->{'UID'} = undef; > >>> > $ac->{'SVR'} = undef; > >>> > $ac->{'PORT'} = undef; > >>> > $ac->{'LOGIN'} = undef; > >>> > $ac->{'PASS'} = undef; > >>> > $pop3C = undef; > >>> > unlink($_[1].".acc"); > >>> > } > >>> > > >>> > sub pop3CError ($$) { > >>> > > >>> > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; > >>> > exit; > >>> > > >>> > } > >>> > > >>> > > >>> > > >>> > > >>> > >From: abez > >>> > >To: Jeremy Aiyadurai > >>> > >CC: victoria-pm@pm.org > >>> > >Subject: Re: Perl 5.8 threads and sockets problem > >>> > >Date: Sun, 23 Feb 2003 20:35:24 -0800 (PST) > >>> > > > >>> > > > >>> > > > >>> > >Here's what I'd do: > >>> > > > >>> > >use IO::Socket qw(:DEFAULT :crlf); > >>> > > > >>> > >my @thr = (); > >>> > >my @Data = ( > >>> > > { 'UID' => "abez", 'SVR' => "lycos.com", 'PORT' => "80", > >>> > >'LOGIN' => "abez", 'PASS' => "******" }, > >>> > > { 'UID' => "casper", 'SVR' => "www.metafilter.com", 'PORT' => >"80", > >>> > >'LOGIN' => "casper", 'PASS' => "*****" }, > >>> > >); > >>> > >my $i = 0; > >>> > > > >>> > >Startup(); > >>> > > > >>> > >foreach my $account (@Data) { > >>> > > $str = " rm -f $account->{UID}.acc "; > >>> > > `$str`; > >>> > >} > >>> > > > >>> > >$| = 0; > >>> > >sub Startup { > >>> > > for (;;) { > >>> > > #Win32::Sleep(4000); > >>> > > foreach my $account (@Data) { > >>> > > #if (-f $account->{'UID'}.".acc") { > >>> > > # next; > >>> > > #} > >>> > > print "Forking $account->{UID}\n"; > >>> > > my $pid = fork(); > >>> > > if ($pid==0) { #child > >>> > > print "Child $account->{UID}\n"; > >>> > > go($account); > >>> > > exit(); > >>> > > } > >>> > > } > >>> > > sleep(10); > >>> > > } > >>> > > } > >>> > > > >>> > > > >>> > > > >>> > > > >>> > >sub go($$$$$) { > >>> > > my $account = shift; > >>> > > > >>> > >my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => > >>> > > $account->{SVR}, > >>> > > PeerPort => $account->{PORT} , Timeout => 60) > >>> > > or pop3CError ($account->{SVR},$account->{PORT}); > >>> > >open(X,">".$account->{UID}.".acc"); > >>> > >close(X); > >>> > >print "in $account->{UID}\n"; > >>> > >print $pop3C "GET /\n"; > >>> > >my @out = <$pop3C>; > >>> > >print join("",@out[0..10]),"\n"; > >>> > >$pop3C->close; > >>> > > > >>> > >$pop3C = undef; > >>> > >unlink($_[1].".acc"); > >>> > >} > >>> > > > >>> > >sub pop3CError ($$) { > >>> > > > >>> > >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; > >>> > >exit; > >>> > > > >>> > >} > >>> > > > >>> > > > >>> > > > >>> > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > >>> > > > >>> > > > hi All, > >>> > > > > >>> > > > Thanks for your help so far. > >>> > > > > >>> > > > I tried threads->create, it made no difference, > >>> > > > as mentioned in the manpage, "The new() method is an alias for > >>>create(). > >>> > >" > >>> > > > > >>> > > > Your Help is much appreciated, > >>> > > > thanks > >>> > > > > >>> > > > Jeremy A. > >>> > > > > >>> > > > >From: abez > >>> > > > >To: Jeremy Aiyadurai > >>> > > > >CC: victoria-pm@pm.org > >>> > > > >Subject: Re: Perl 5.8 threads and sockets problem > >>> > > > >Date: Sun, 23 Feb 2003 18:38:16 -0800 (PST) > >>> > > > > > >>> > > > > > >>> > > > >First of all try threads->create, rather than new. Other than >that > >>>I'm > >>> > >too > >>> > > > >dizzy to really help right now (flu). > >>> > > > > > >>> > > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: > >>> > > > > > >>> > > > > > > >>> > > > > > Hello all, > >>> > > > > > > >>> > > > > > I am new to the group. > >>> > > > > > I have a problem involving sockets and threads. > >>> > > > > > > >>> > > > > > Basically, I want to be able to do two or more pop3 sessions > >>> > > > >simultaniously > >>> > > > > > using a list of different pop3 accounts. > >>> > > > > > my problem is, I can logon to the first account, but when > >>> > > > > > it comes to the second account's turn (in the second >thread), > >>>the > >>> > >socket > >>> > > > > > cannot be created. > >>> > > > > > > >>> > > > > > I am new to using threads and have little knowledge of >sockets. > >>> > > > > > > >>> > > > > > Your Help is much appreciated, > >>> > > > > > > >>> > > > > > Thanks, > >>> > > > > > > >>> > > > > > Jeremy A. > >>> > > > > > > >>> > > > > > Below is my test script I am having trouble with. > >>> > > > > > > >>> > > > > > > >>> > > > > > #----------------------------------------------------- > >>> > > > > > use threads; > >>> > > > > > use Win32; > >>> > > > > > use IO::Socket qw(:DEFAULT :crlf); > >>> > > > > > > >>> > > > > > > >>> > > > > > my @thr; > >>> > > > > > my @Data; > >>> > > > > > $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", > >>>'PORT' => > >>> > > > >"110", > >>> > > > > > 'LOGIN' => "account1", 'PASS' => "******" }; > >>> > > > > > $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", >'PORT' > >>>=> > >>> > >"110", > >>> > > > > > 'LOGIN' => "account2", 'PASS' => "*****" }; > >>> > > > > > my $i = 0; > >>> > > > > > > >>> > > > > > sub Startup { > >>> > > > > > while (1) { > >>> > > > > > Win32::Sleep(4000); > >>> > > > > > foreach my $account (@Data) > >>> > > > > > { > >>> > > > > > if(!open(T,"".$account->{'UID'}.".acc")) > >>> > > > > > { > >>> > > > > > Win32::Sleep(40); > >>> > > > > > if($i != 0) > >>> > > > > > { > >>> > > > > > $i = $i + 1; > >>> > > > > > } > >>> > > > > > $thr[$i] = > >>> > > > > > > >>> > > > > >>> > > > >>> > >threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account->{'PORT'},$acc >ount->{'LOGIN'},$account->{'PASS'}); > >>> > > > > > $thr[$i]->join; > >>> > > > > > }else > >>> > > > > > { > >>> > > > > > close(T); > >>> > > > > > } > >>> > > > > > $i = $i - 1; > >>> > > > > > > >>> > > > > > } > >>> > > > > > } > >>> > > > > > @AC = -1; > >>> > > > > > } > >>> > > > > > > >>> > > > > > Startup(); > >>> > > > > > > >>> > > > > > > >>> > > > > > > >>> > > > > > sub go($$$$$) { > >>> > > > > > print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n"; > >>> > > > > > > >>> > > > > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr >=> > >>> > >"$_[1]", > >>> > > > > > PeerPort => $_[2], Timeout => 60) or pop3CError >($_[1],$_[2]); > >>> > > > > > open(X,">".$_[1].".acc"); > >>> > > > > > close(X); > >>> > > > > > print "in $_[1]\n"; > >>> > > > > > sleep(1); > >>> > > > > > pop3close($pop3C); > >>> > > > > > $pop3C = undef; > >>> > > > > > unlink($_[1].".acc"); > >>> > > > > > } > >>> > > > > > > >>> > > > > > > >>> > > > > > sub pop3CError ($$) { > >>> > > > > > > >>> > > > > > print "Cannot connect to the the Pop3 server:$_[0], > >>>port:$_[1]\n"; > >>> > > > > > exit; > >>> > > > > > > >>> > > > > > } > >>> > > > > > > >>> > > > > > > >>> > > > > > sub pop3close ($) { > >>> > > > > > if ($_[0]) { > >>> > > > > > shutdown ($_[0], 2); > >>> > > > > > } > >>> > > > > > } > >>> > > > > > #----------------------------------------------------- > >>> > > > > > > >>> > > > > > > >>> > > > > > > >>> > > > > > > >>> > > > > > > >>> > > > > > > >>>_________________________________________________________________ > >>> > > > > > The new MSN 8: smart spam protection and 2 months FREE* > >>> > > > > > http://join.msn.com/?page=features/junkmail > >>> > > > > > > >>> > > > > > >>> > > > >-- > >>> > > > >abez ------------------------------------------ > >>> > > > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) > >>> > > > >------------------------------------------ abez > >>> > > > > >>> > > > > >>> > > > >_________________________________________________________________ > >>> > > > Add photos to your messages with MSN 8. Get 2 months FREE*. > >>> > > > http://join.msn.com/?page=features/featuredemail > >>> > > > > >>> > > > >>> > >-- > >>> > >abez ------------------------------------------ > >>> > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) > >>> > >------------------------------------------ abez > >>> > > >>> > > >>> > _________________________________________________________________ > >>> > Help STOP SPAM with the new MSN 8 and get 2 months FREE* > >>> > http://join.msn.com/?page=features/junkmail > >>> > > >>> > >>>-- > >>>abez ------------------------------------------ > >>>http://www.abez.ca/ Abram Hindle (abez@abez.ca) > >>>------------------------------------------ abez > >> > >> > >>_________________________________________________________________ > >>Help STOP SPAM with the new MSN 8 and get 2 months FREE* > >>http://join.msn.com/?page=features/junkmail > >> > > > > > >_________________________________________________________________ > >Tired of spam? Get advanced junk mail protection with MSN 8. > >http://join.msn.com/?page=features/junkmail > _________________________________________________________________ STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail From Peter at PSDT.com Thu Feb 27 15:00:41 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:17 2004 Subject: Perl 5.8 threads and sockets problem In-Reply-To: Message-ID: <4.3.2.7.2.20030227125841.00aae260@shell2.webquarry.com> At 12:55 PM 2/27/03 -0800, Jeremy Aiyadurai wrote: >Thanks for the advice. > >I added the "strict" and "warnings". >i also did perl -c *.pl. > >I get this output just before the script exits: >"... >Forking Jon >Child Jeremy >Child Jon >in Jeremy >in Jon >Forking Jeremy >Use of uninitialized value in numeric eq (==) at >E:\backup\perlstuff\project\mai >lclient\Emia4Win\Emia4Win-EmiaSVC2003.02.24perlapp-selectslice\pig2.pl >line 33. Your fork() call returned undef, which indicates that it failed. You're not calling fork() robustly. If fork returns undef print $! to see why it failed. One type of error is potentially recoverable. Do perldoc perlipc to see more information. >Child Jeremy >in Jeremy" > >Your help is greatly and always appreciated. >Thanks, > >Jeremy A. > > >>From: nkuipers >>To: "Jeremy Aiyadurai" >>CC: victoria-pm@pm.org >>Subject: RE: Perl 5.8 threads and sockets problem >>Date: Thu, 27 Feb 2003 12:39:47 -0800 >> >> >The following script works for a couple seconds\minutes then exits (i dont >> >know why) >> >>I really think the first thing you need to do is figure out why. Is the >>strict pragma called Strict in Win32 Perl? Also you should use warnings: >> >>use strict; >>use warnings; >> >>and then run >> >>perl -c yourscript >> >>You might try wrapping chunks of code in eval and seeing what happens too. >> >>What is the $i variable for? Why are you turning off the >>autoflush? What are >>you using the X filehandle for? You open it in go() and then ensure it is >>closed right away, in the next statement or failing that, as the first >>statement in the call to pop3CError(). I am not familiar with >>sockets at all, >>but I see no writing to the X filehandle anywhere... >> >> >> >> >#---------------------------- >> > >> >use IO::Socket qw(:DEFAULT :crlf); >> >use Strict; >> > >> > >> >my $pop3C; >> >my @thr = (); >> >my @Data = ( >> > { 'UID' => "Jeremy", 'SVR' => "mail.host.com", 'PORT' => "110", >> >'LOGIN' => "jerdoe", 'PASS' => "****" }, >> > { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", >> >'LOGIN' => "jondoe", 'PASS' => "*******" }, >> >); >> >my $i = 0; >> > >> >Startup(); >> > >> > >> > >> > >> >sub Startup { >> > $| = 0; >> > for (;;) { >> > foreach my $account (@Data) { >> > if (-f $account->{'UID'}.".acc") { >> > next; >> > } >> > print "Forking $account->{UID}\n"; >> > >> > #child >> > my $pid = fork(); >> > if ($pid == 0){ >> > print "Child $account->{UID}\n"; >> > go($account); >> > $account = undef; >> > exit(0); >> > } >> > >> > } >> > >> > sleep(1); >> > } >> > } >> > >> > >> > >> >sub go() { >> > my $ac = shift; >> >open(X,">".$ac->{UID}.".acc"); >> >$pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >> > $ac->{SVR}, >> > PeerPort => $ac->{PORT} , Timeout => 0) >> > and close(X) or pop3CError ($ac->{SVR},$ac->{PORT}); >> >print "in $ac->{UID}\n"; >> >$pop3C->close; >> >unlink($ac->{'UID'}.".acc"); >> >$ac->{'UID'} = undef; >> >$ac->{'SVR'} = undef; >> >$ac->{'PORT'} = undef; >> >$ac->{'LOGIN'} = undef; >> >$ac->{'PASS'} = undef; >> >$pop3C = undef; >> >} >> > >> >sub pop3CError ($$) { >> >close(X); >> >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >> >exit; >> > >> >} >> >-------------------------------------- >> >>From: "Jeremy Aiyadurai" >> >>To: victoria-pm@pm.org >> >>Subject: Re: Perl 5.8 threads and sockets problem >> >>Date: Tue, 25 Feb 2003 16:28:55 -0800 >> > >> >>Hi all, >> >> >> >>Thanks for all your help so far. >> >> >> >>I am still having having problems with the forking. >> >>the script will only run for 30 or so seconds, >> >>before it exits. >> >> >> >>I am stumped on how to keep it running continously. >> >> >> >>The following is the code >> >>............................................... >> >>use IO::Socket qw(:DEFAULT :crlf); >> >> >> >> >> >>my $pop3C; >> >>my @thr = (); >> >>my @Data = ( >> >> { 'UID' => "Jeremy", 'SVR' => "mail.h.y", 'PORT' => "110", >> >>'LOGIN' => "jerdoe", 'PASS' => "******" }, >> >> { 'UID' => "Jon", 'SVR' => "mail.h.t", 'PORT' => "110", >> >>'LOGIN' => "jondoe", 'PASS' => "****" }, >> >>); >> >>my $i = 0; >> >> >> >>Startup(); >> >> >> >> >> >>sub Startup { >> >> $| = 0; >> >> for (;;) { >> >> foreach my $account (@Data) { >> >> if (-f $account->{'UID'}.".acc") { >> >> next; >> >> } >> >> print "Forking $account->{UID}\n"; >> >> my $pid = fork(); >> >> if ($pid == 0){ >> >> # in child >> >> print "Child $account->{UID}\n"; >> >> go($account); >> >> $account = undef; >> >> exit(0); >> >> } >> >> >> >> } >> >> >> >> sleep(1); >> >> } >> >> } >> >> >> >> >> >> >> >>sub go() { >> >> my $ac = shift; >> >> >> >>$pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >> >> $ac->{SVR}, >> >> PeerPort => $ac->{PORT} , Timeout => 0) >> >> or pop3CError ($ac->{SVR},$ac->{PORT}); >> >>open(X,">".$ac->{UID}.".acc"); >> >>close(X); >> >>print "in $ac->{UID}\n"; >> >>$pop3C->close; >> >>unlink($ac->{'UID'}.".acc"); >> >>$ac->{'UID'} = undef; >> >>$ac->{'SVR'} = undef; >> >>$ac->{'PORT'} = undef; >> >>$ac->{'LOGIN'} = undef; >> >>$ac->{'PASS'} = undef; >> >>$pop3C = undef; >> >>} >> >> >> >>sub pop3CError ($$) { >> >> >> >>print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >> >>exit; >> >> >> >>} >> >>.................................................. >> >> >> >> >> >>Your help is much appreciated. >> >>Thanks, >> >> >> >>Jeremy A. >> >> >> >> >> >> >> >> >> >> >> >> >> >>>From: abez >> >>>To: Jeremy Aiyadurai >> >>>CC: victoria-pm@pm.org >> >>>Subject: Re: Perl 5.8 threads and sockets problem >> >>>Date: Sun, 23 Feb 2003 22:10:03 -0800 (PST) >> >>> >> >>> >> >>>Well uncomment these lines, so that you "locking" works. >> >>> > #if (-f $account->{'UID'}.".acc") { >> >>> > # next; >> >>> > #} >> >>> >> >>>I don't know WIN32 too well to guess about the memory but you might want >> >>>to >> >>>print before that exit where $account = undef; exit; Just print you're >> >>>closing >> >>>you might get better information. >> >>> >> >>>Also print debugging info to STDERR if possible it's default unbuffered. >> >>> >> >>>call wait() before you call sleep(1) and it will make sure your processes >> >>>aren't zombified. >> >>> >> >>> >> >>>On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >> >>> >> >>> > >> >>> > Hi again, >> >>> > >> >>> > Thanks for all your help so far. >> >>> > I monitored my memory usage while running the script. >> >>> > It appears to slowly eat up memory. If i were to run this script day >> >>>and >> >>> > night as long as I keep my computer on like a server, It would >> probably >> >>> > crash my system even though I have alot of SDRAM. >> >>> > Also, the script will run for a while, then crash and exit, does this >> >>>have >> >>> > to do with fork (thread) races? >> >>> > eg. it ends like this >> >>> > " >> >>> > in Jeremy >> >>> > in Jon >> >>> > Forking Jeremy >> >>> > Forking Jon >> >>> > Child Jeremy >> >>> > Child Jon >> >>> > in Jeremy >> >>> > in Jon >> >>> > Forking Jeremy >> >>> > Child Jeremy >> >>> > in Jeremy" - exits here? don't know why? when three jeremy's are in >> >>> > sequence, the program terminates. >> >>> > >> >>> > Your Help is greatly appreciated >> >>> > >> >>> > Thanks, >> >>> > Jeremy A. >> >>> > >> >>> > here is the script now with the prints "Forking $UID","Child $UID" and >> >>>"in >> >>> > $UID". >> >>> > --------------------------- >> >>> > use IO::Socket qw(:DEFAULT :crlf); >> >>> > use Win32; >> >>> > >> >>> > >> >>> > my @thr = (); >> >>> > my @Data = ( >> >>> > { 'UID' => "Jeremy", 'SVR' => "mail.host.net", 'PORT' => "110", >> >>> > 'LOGIN' => "jerdoe", 'PASS' => "********" }, >> >>> > { 'UID' => "Jon", 'SVR' => "mail.host.net", 'PORT' => "110", >> >>> > 'LOGIN' => "jondoe", 'PASS' => "*****" }, >> >>> > ); >> >>> > my $i = 0; >> >>> > >> >>> > Startup(); >> >>> > >> >>> > #foreach my $account (@Data) { >> >>> > # $str = " rm -f $account->{UID}.acc "; >> >>> > # `$str`; >> >>> > #} >> >>> > >> >>> > >> >>> > sub Startup { >> >>> > for (;;) { >> >>> > #Win32::Sleep(4000); >> >>> > $| = 0; >> >>> > foreach my $account (@Data) { >> >>> > #if (-f $account->{'UID'}.".acc") { >> >>> > # next; >> >>> > #} >> >>> > print "Forking $account->{UID}\n"; >> >>> > my $pid = fork(); >> >>> > if ($pid==0) { #child >> >>> > print "Child $account->{UID}\n"; >> >>> > go($account); >> >>> > $account = undef; >> >>> > exit(); >> >>> > } >> >>> > >> >>> > } >> >>> > sleep(1); >> >>> > } >> >>> > } >> >>> > >> >>> > >> >>> > >> >>> > >> >>> > sub go() { >> >>> > my $ac = shift; >> >>> > >> >>> > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >> >>> > $ac->{SVR}, >> >>> > PeerPort => $ac->{PORT} , Timeout => 0) >> >>> > or pop3CError ($ac->{SVR},$ac->{PORT}); >> >>> > open(X,">".$ac->{UID}.".acc"); >> >>> > close(X); >> >>> > print "in $ac->{UID}\n"; >> >>> > Win32::Sleep(4000); >> >>> > $pop3C->close; >> >>> > $ac->{'UID'} = undef; >> >>> > $ac->{'SVR'} = undef; >> >>> > $ac->{'PORT'} = undef; >> >>> > $ac->{'LOGIN'} = undef; >> >>> > $ac->{'PASS'} = undef; >> >>> > $pop3C = undef; >> >>> > unlink($_[1].".acc"); >> >>> > } >> >>> > >> >>> > sub pop3CError ($$) { >> >>> > >> >>> > print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >> >>> > exit; >> >>> > >> >>> > } >> >>> > >> >>> > >> >>> > >> >>> > >> >>> > >From: abez >> >>> > >To: Jeremy Aiyadurai >> >>> > >CC: victoria-pm@pm.org >> >>> > >Subject: Re: Perl 5.8 threads and sockets problem >> >>> > >Date: Sun, 23 Feb 2003 20:35:24 -0800 (PST) >> >>> > > >> >>> > > >> >>> > > >> >>> > >Here's what I'd do: >> >>> > > >> >>> > >use IO::Socket qw(:DEFAULT :crlf); >> >>> > > >> >>> > >my @thr = (); >> >>> > >my @Data = ( >> >>> > > { 'UID' => "abez", 'SVR' => "lycos.com", 'PORT' => "80", >> >>> > >'LOGIN' => "abez", 'PASS' => "******" }, >> >>> > > { 'UID' => "casper", 'SVR' => "www.metafilter.com", 'PORT' => "80", >> >>> > >'LOGIN' => "casper", 'PASS' => "*****" }, >> >>> > >); >> >>> > >my $i = 0; >> >>> > > >> >>> > >Startup(); >> >>> > > >> >>> > >foreach my $account (@Data) { >> >>> > > $str = " rm -f $account->{UID}.acc "; >> >>> > > `$str`; >> >>> > >} >> >>> > > >> >>> > >$| = 0; >> >>> > >sub Startup { >> >>> > > for (;;) { >> >>> > > #Win32::Sleep(4000); >> >>> > > foreach my $account (@Data) { >> >>> > > #if (-f $account->{'UID'}.".acc") { >> >>> > > # next; >> >>> > > #} >> >>> > > print "Forking $account->{UID}\n"; >> >>> > > my $pid = fork(); >> >>> > > if ($pid==0) { #child >> >>> > > print "Child $account->{UID}\n"; >> >>> > > go($account); >> >>> > > exit(); >> >>> > > } >> >>> > > } >> >>> > > sleep(10); >> >>> > > } >> >>> > > } >> >>> > > >> >>> > > >> >>> > > >> >>> > > >> >>> > >sub go($$$$$) { >> >>> > > my $account = shift; >> >>> > > >> >>> > >my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >> >>> > > $account->{SVR}, >> >>> > > PeerPort => $account->{PORT} , Timeout => 60) >> >>> > > or pop3CError ($account->{SVR},$account->{PORT}); >> >>> > >open(X,">".$account->{UID}.".acc"); >> >>> > >close(X); >> >>> > >print "in $account->{UID}\n"; >> >>> > >print $pop3C "GET /\n"; >> >>> > >my @out = <$pop3C>; >> >>> > >print join("",@out[0..10]),"\n"; >> >>> > >$pop3C->close; >> >>> > > >> >>> > >$pop3C = undef; >> >>> > >unlink($_[1].".acc"); >> >>> > >} >> >>> > > >> >>> > >sub pop3CError ($$) { >> >>> > > >> >>> > >print "Cannot connect to the the Pop3 server:$_[0], port:$_[1]\n"; >> >>> > >exit; >> >>> > > >> >>> > >} >> >>> > > >> >>> > > >> >>> > > >> >>> > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >> >>> > > >> >>> > > > hi All, >> >>> > > > >> >>> > > > Thanks for your help so far. >> >>> > > > >> >>> > > > I tried threads->create, it made no difference, >> >>> > > > as mentioned in the manpage, "The new() method is an alias for >> >>>create(). >> >>> > >" >> >>> > > > >> >>> > > > Your Help is much appreciated, >> >>> > > > thanks >> >>> > > > >> >>> > > > Jeremy A. >> >>> > > > >> >>> > > > >From: abez >> >>> > > > >To: Jeremy Aiyadurai >> >>> > > > >CC: victoria-pm@pm.org >> >>> > > > >Subject: Re: Perl 5.8 threads and sockets problem >> >>> > > > >Date: Sun, 23 Feb 2003 18:38:16 -0800 (PST) >> >>> > > > > >> >>> > > > > >> >>> > > > >First of all try threads->create, rather than new. Other >> than that >> >>>I'm >> >>> > >too >> >>> > > > >dizzy to really help right now (flu). >> >>> > > > > >> >>> > > > >On Sun, 23 Feb 2003, Jeremy Aiyadurai wrote: >> >>> > > > > >> >>> > > > > > >> >>> > > > > > Hello all, >> >>> > > > > > >> >>> > > > > > I am new to the group. >> >>> > > > > > I have a problem involving sockets and threads. >> >>> > > > > > >> >>> > > > > > Basically, I want to be able to do two or more pop3 sessions >> >>> > > > >simultaniously >> >>> > > > > > using a list of different pop3 accounts. >> >>> > > > > > my problem is, I can logon to the first account, but when >> >>> > > > > > it comes to the second account's turn (in the second thread), >> >>>the >> >>> > >socket >> >>> > > > > > cannot be created. >> >>> > > > > > >> >>> > > > > > I am new to using threads and have little knowledge of >> sockets. >> >>> > > > > > >> >>> > > > > > Your Help is much appreciated, >> >>> > > > > > >> >>> > > > > > Thanks, >> >>> > > > > > >> >>> > > > > > Jeremy A. >> >>> > > > > > >> >>> > > > > > Below is my test script I am having trouble with. >> >>> > > > > > >> >>> > > > > > >> >>> > > > > > #----------------------------------------------------- >> >>> > > > > > use threads; >> >>> > > > > > use Win32; >> >>> > > > > > use IO::Socket qw(:DEFAULT :crlf); >> >>> > > > > > >> >>> > > > > > >> >>> > > > > > my @thr; >> >>> > > > > > my @Data; >> >>> > > > > > $Data[0] = { 'UID' => "Jeremy", 'SVR' => "mail.host.net", >> >>>'PORT' => >> >>> > > > >"110", >> >>> > > > > > 'LOGIN' => "account1", 'PASS' => "******" }; >> >>> > > > > > $Data[1] = { 'UID' => "Dave", 'SVR' => "mail.bost.com", 'PORT' >> >>>=> >> >>> > >"110", >> >>> > > > > > 'LOGIN' => "account2", 'PASS' => "*****" }; >> >>> > > > > > my $i = 0; >> >>> > > > > > >> >>> > > > > > sub Startup { >> >>> > > > > > while (1) { >> >>> > > > > > Win32::Sleep(4000); >> >>> > > > > > foreach my $account (@Data) >> >>> > > > > > { >> >>> > > > > > if(!open(T,"".$account->{'UID'}.".acc")) >> >>> > > > > > { >> >>> > > > > > Win32::Sleep(40); >> >>> > > > > > if($i != 0) >> >>> > > > > > { >> >>> > > > > > $i = $i + 1; >> >>> > > > > > } >> >>> > > > > > $thr[$i] = >> >>> > > > > > >> >>> > > > >> >>> > > >> >>> >> >threads->new(\&go,$account->{'UID'},$account->{'SVR'},$account->{'PO >> RT'},$acc >>ount->{'LOGIN'},$account->{'PASS'}); >> >>> > > > > > $thr[$i]->join; >> >>> > > > > > }else >> >>> > > > > > { >> >>> > > > > > close(T); >> >>> > > > > > } >> >>> > > > > > $i = $i - 1; >> >>> > > > > > >> >>> > > > > > } >> >>> > > > > > } >> >>> > > > > > @AC = -1; >> >>> > > > > > } >> >>> > > > > > >> >>> > > > > > Startup(); >> >>> > > > > > >> >>> > > > > > >> >>> > > > > > >> >>> > > > > > sub go($$$$$) { >> >>> > > > > > print "$_[0],$_[1],$_[2],$_[3],$_[4],$_[5],$_[6]\n"; >> >>> > > > > > >> >>> > > > > > my $pop3C = IO::Socket::INET->new(Proto => 'tcp', PeerAddr => >> >>> > >"$_[1]", >> >>> > > > > > PeerPort => $_[2], Timeout => 60) or pop3CError ($_[1],$_[2]); >> >>> > > > > > open(X,">".$_[1].".acc"); >> >>> > > > > > close(X); >> >>> > > > > > print "in $_[1]\n"; >> >>> > > > > > sleep(1); >> >>> > > > > > pop3close($pop3C); >> >>> > > > > > $pop3C = undef; >> >>> > > > > > unlink($_[1].".acc"); >> >>> > > > > > } >> >>> > > > > > >> >>> > > > > > >> >>> > > > > > sub pop3CError ($$) { >> >>> > > > > > >> >>> > > > > > print "Cannot connect to the the Pop3 server:$_[0], >> >>>port:$_[1]\n"; >> >>> > > > > > exit; >> >>> > > > > > >> >>> > > > > > } >> >>> > > > > > >> >>> > > > > > >> >>> > > > > > sub pop3close ($) { >> >>> > > > > > if ($_[0]) { >> >>> > > > > > shutdown ($_[0], 2); >> >>> > > > > > } >> >>> > > > > > } >> >>> > > > > > #----------------------------------------------------- >> >>> > > > > > >> >>> > > > > > >> >>> > > > > > >> >>> > > > > > >> >>> > > > > > >> >>> > > > > > >> >>>_________________________________________________________________ >> >>> > > > > > The new MSN 8: smart spam protection and 2 months FREE* >> >>> > > > > > http://join.msn.com/?page=features/junkmail >> >>> > > > > > >> >>> > > > > >> >>> > > > >-- >> >>> > > > >abez ------------------------------------------ >> >>> > > > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >> >>> > > > >------------------------------------------ abez >> >>> > > > >> >>> > > > >> >>> > > > _________________________________________________________________ >> >>> > > > Add photos to your messages with MSN 8. Get 2 months FREE*. >> >>> > > > http://join.msn.com/?page=features/featuredemail >> >>> > > > >> >>> > > >> >>> > >-- >> >>> > >abez ------------------------------------------ >> >>> > >http://www.abez.ca/ Abram Hindle (abez@abez.ca) >> >>> > >------------------------------------------ abez >> >>> > >> >>> > >> >>> > _________________________________________________________________ >> >>> > Help STOP SPAM with the new MSN 8 and get 2 months FREE* >> >>> > http://join.msn.com/?page=features/junkmail >> >>> > >> >>> >> >>>-- >> >>>abez ------------------------------------------ >> >>>http://www.abez.ca/ Abram Hindle (abez@abez.ca) >> >>>------------------------------------------ abez >> >> >> >> >> >>_________________________________________________________________ >> >>Help STOP SPAM with the new MSN 8 and get 2 months FREE* >> >>http://join.msn.com/?page=features/junkmail >> >> >> > >> > >> >_________________________________________________________________ >> >Tired of spam? Get advanced junk mail protection with MSN 8. >> >http://join.msn.com/?page=features/junkmail > > >_________________________________________________________________ >STOP MORE SPAM with the new MSN 8 and get 2 months FREE* >http://join.msn.com/?page=features/junkmail > -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From nkuipers at uvic.ca Fri Feb 28 14:37:44 2003 From: nkuipers at uvic.ca (nkuipers) Date: Wed Aug 4 00:11:17 2004 Subject: Next meeting Message-ID: <3E5FE0FD@wm2.uvic.ca> >Basically I will have a look at those BioPerl modules, but any changes for >improvement will be done at the meeting as a group effort. Hrmmmm I think we have a miscommunication here, I wasn't proposing hacking up a BioPerl module, I was proposing using my own BIO modules as source material for illustrating how to build CPAN-standard code, hacking them up as we see fit in the process...Of course, we can grab actual BioPerl code too. :) >Oh right, I forgot that part. Fine, we'll just make it a date when you >and Nathan can make. The week of the 24th is totally out for me. >Also, someone else would have to bring a portable computer with the requisite >BioPerl modules on it, and a decent text editor. I can send my modules to Peter. And as for bioperl, it's easy to install, takes 5 minutes or so. Nathanael From darren at DarrenDuncan.net Fri Feb 28 14:49:47 2003 From: darren at DarrenDuncan.net (Darren Duncan) Date: Wed Aug 4 00:11:17 2004 Subject: Next meeting In-Reply-To: <3E5FE0FD@wm2.uvic.ca> Message-ID: On Fri, 28 Feb 2003, nkuipers wrote: > >Basically I will have a look at those BioPerl modules, but any changes for > >improvement will be done at the meeting as a group effort. > > Hrmmmm I think we have a miscommunication here, I wasn't proposing hacking up > a BioPerl module, I was proposing using my own BIO modules as source material > for illustrating how to build CPAN-standard code, hacking them up as we see > fit in the process...Of course, we can grab actual BioPerl code too. :) That's perfectly fine. I misunderstood what you were saying at the last meeting. In fact, there should be a lot more lasting benefits for hacking your Bio modules than the bioperl ones, since you can use the new versions, but we would never commit any changes to bioperl back to the source. So, I will need *your* modules provided on whatever laptop is being brought to the march meeting. It would also help if you emailed me up-to-date versions so I can peruse them in advance. -- Darren Duncan From peter at PSDT.com Fri Feb 28 21:51:53 2003 From: peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:17 2004 Subject: Victoria.pm does it again Message-ID: <4.3.2.7.2.20030228194947.00c1fc80@shell2.webquarry.com> 3 days ahead of a BioPerl book review on perl.com we were there with Nathanael's excellent talk! http://www.perl.com/pub/a/2003/02/27/review.html BTW, I will be the guest at a dinner meeting of LA.pm next Tuesday. -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/ From Peter at PSDT.com Fri Feb 28 21:53:40 2003 From: Peter at PSDT.com (Peter Scott) Date: Wed Aug 4 00:11:17 2004 Subject: Next meeting In-Reply-To: <3E5FE0FD@wm2.uvic.ca> Message-ID: <4.3.2.7.2.20030228195225.00c16990@shell2.webquarry.com> At 12:37 PM 2/28/03 -0800, nkuipers wrote: >The week of the 24th is totally out for me. Okay, so pick something the week of the 17th. I'll bring my laptop; give me a complete list of the modules you want installed. One way to do that: in one of the programs that uses your modules, stick: END { print "$_\n" for sort keys %INC } -- Peter Scott Pacific Systems Design Technologies http://www.perldebugged.com/