Ten rules to becoming a Python community member.
Follow these simply rules to become an accepted member of the Python community. 1. Bash rantingrick and Xah Lee every chance you get. 2. Bash people who bash rick or xah because their basing made rick's or xah's words pass through your spam filter. 3. Post links to xkcd as often as you can. Don't worry if they have been posted a thousand times, just post them because it equals "geek cool points". 4. When the chance presents itself, make snide comments about lisp and perl; but NEVER about Ruby! (even though Ruby is Perl's micro minion!). 5. Use fancy words like "tail recursion", just because you read about it on Guido's blog once (even if you have no idea what that means)! 6. Engage in heated and pointless discussions as to whether Python is "pass-by-reference" or "pass-by-value" even if you have no idea what the hell you are talking about. 7. Play devils advocate often e.g., If someone hates Tkinter: then argue how great Tkinter is regardless of how much you actually care, use, or know about the module. Likewise if someone likes Tkinter: then argue how terrible Tkinter is and how Python does not need any GUI library; again, regardless of how much you actually care, use, or know about the module. 8. Use "e.g." as many times as you can! (e.g. e.g.) If you use "e.g." more than ten times in a single post, you will get an invite to Guido's next birthday party; where you'll be forced to do shots whist walking the balcony railing wearing wooden shoes! 9. Never use the word "previously" or the phrase "in the past"; just dumb it down with "used to". 10. Finally, if you get caught using the word "that" incredibly excessively, just hope that nobody notices that that that you are really GvR in disguise. -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I convert String into Date object
I found this solution. Python: Convert String Date to Date Object http://slaptijack.com/programming/python-convert-string-date-to-date-object/ On Aug 13, 3:14 pm, MrPink wrote: > Is this the correct way to convert a String into a Date? > I only have dates and no time. > > import time, datetime > > oDate = time.strptime('07/27/2011', '%m/%d/%Y') > print oDate > > Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: allow line break at operators
On Aug 12, 4:06 pm, Seebs wrote: > On 2011-08-12, Chris Angelico wrote: > > > Why is left-to-right inherently more logical than > > multiplication-before-addition? > > I'd say it's certainly "more Pythonic in a vacuum". > Multiplication-before-addition, and all the related rules, require > you to know a lot of special rules which are not visible in the > code, and many of which have no real logical basis. Left-to-right > is, if nothing else, the way the majority of us read. > > The problem is that since everyone's used precedence before, not using > it violates the principle of least astonishment. And repeatedly propagating a foolish consistency is well, FOOLISH! This problem invades every aspect of technology. Who was the idiot that decided it was okay to close SOME html tag and NOT close others? Since HTML is made to be read by machines why the hell would someone knowingly induce disorder? Which then leads to needing more logic to parse? But even more insane is why HTML has been allowed to be so disorderly for so long. Where is the need to be consistent? I tell you how to solve this, you solve it with plagues. Plagues of syntax errors will teach the unrighteous the err of their ways. -- http://mail.python.org/mailman/listinfo/python-list
Re: allow line break at operators
On Aug 12, 7:39 pm, Seebs wrote: > Consider the hypothetical array syntax: > > a = [ > 1, > 2 > b = [ > 3, > 4 > > This *bugs* me. It's perfectly legible, and if you define it that way, it's > unambiguous and everything, but... It bugs me. I want beginnings to have > an actual corresponding end. It "almost" seems as if you have a valid point here until you consider that conditionals and blocks are ridged structures that must be defined under a strict set of syntactical rules with keywords and indentation. Whereas the list, dict, set, and tuple absolutely MUST have an explicit beginning AND an explicit end due to their free-form nature. You could create some strict rules for defining "X-literals" and remove any need for start and end tags however i see no need to do so. -- http://mail.python.org/mailman/listinfo/python-list
Data issues with Django and Apache
I'm devleoping a website using the Django framework along with Apache, and I'm seeing some odd data issues. During the course of navigating through the website content, a user will cause the creation of some data records with a limited lifespan. These data records have a create_dt field which is automatically set to the time that they were created, and an expire_dt field which is equal to create_dt plus ten minutes. The problem is that I get conflicting results as to whether these temporary records have reached their expiration date, depending if I search for them via an Apache web call or if I do the search locally from a python shell. And to make it weirder, the conflicts go away if I stop and restart the Apache server, although any new records created after this point will still exhibit the issue. Are there any known "gotchas" when using Django with Apache? It almost seems like Apache is maintaining its own persistent session or something, and restarting Apache causes the session to be flushed. -- John Gordon A is for Amy, who fell down the stairs gor...@panix.com B is for Basil, assaulted by bears -- Edward Gorey, "The Gashlycrumb Tinies" -- http://mail.python.org/mailman/listinfo/python-list
Re: allow line break at operators
On Aug 12, 7:39 pm, Seebs wrote: > I was overjoyed when I saw that Ruby would let me write 1_048_576. I'll have to admit that Ruby has a few very interesting ideas, this being one of them. We all know how impossible it can be to eyeball parse a very long number like this. Having the interpretor ignore underscores in a number was very wise indeed! However i really hate the fact that Ruby FORCES you to use OOP. I LOVE OOP, however there are times when you just don't need that level of machinery to solve a problem. A good example is when scripting an API. Most times all you need is a few module level procedures and some simple logic. Try that with Ruby, then try that with Python, you'll be switching to Python in no time! PS: And before any Matz lovers start complaining: Yes, i know you can do procedural programming with ruby HOWEVER it suffers many pitfall due to (1) Ruby's scoping issues and (2) Ruby's explicit module declaration (which is more indirect than the first). -- http://mail.python.org/mailman/listinfo/python-list
Re: allow line break at operators
On Aug 12, 7:39 pm, Seebs wrote: > Well, that's the thing. > > In a case like: > > if foo: > if bar: > blah > blah > > I notice that *NOTHING* lines up with "if bar:". And that affects me > about the way unmatched brackets do. For me, i believe it was a grave mistake to allow "user defined indention" within a python module. Not only that, but allowing indentation to be inconsistent (within the same module) not only worse, it's insane! I could have "slightly" understood giving people a choice of how many indents to use however i cannot fathom the idiocy of allowing inconsistent indentation within the same module! Although GvR is no doubt a brilliant mind he keeps making the same mistakes over and over again in the name of muti-stylism. ¡Ay, caramba! Not that i find it *impossible* to read inconsistent indentation mind you, but that i find it blasphemous to the name of consistency. Programming languages MUST be consistent. Python should allow one and only one obvious way to indent a block; whether it be by a single tab char or by four spaces i don't care! But for crikey's sake pick one of them and stick with it!!! -- http://mail.python.org/mailman/listinfo/python-list
Re: allow line break at operators
On Aug 12, 5:03 pm, Steven D'Aprano wrote: > Responding to Rick's standard {EDIT} posts > is like wrestling with a {EDIT} > [...] > Save yourself a lot of aggravation and kill-file him now. Kindly allow Walter E. Kurtz to shine some light on this situation: """ Pig after pig, cow after cow, village after village, army after army. And they call me an assassin. What do you call it when the assassins accuse the assassin? They lie.. they lie and we have to be merciful for those who lie. Those nabobs. I hate them. How I hate them...""" -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I convert String into Date object
In article <83822ecb-3643-42c6-a2bf-0187c07d3...@a10g2000yqn.googlegroups.com>, MrPink wrote: > Is this the correct way to convert a String into a Date? > I only have dates and no time. You have already received a number of good replies, but let me throw out one more idea. If you ever need to do something with dates and times which the standard datetime module can't handle, take a look at the excellent dateutil module by Gustavo Niemeyer (http://labix.org/python-dateutil). -- http://mail.python.org/mailman/listinfo/python-list
Re: Relative import from script with same name as package
On Sun, Aug 14, 2011 at 12:55 AM, OKB (not okblacke) wrote: > sys.path = sys.path[1:] + [''] > > (That is, move the current directory to the end of the search path > instead of the beginning.) > Or, equivalently: sys.path.append(sys.path.pop(0)) ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Relative import from script with same name as package
OKB (not okblacke) wrote: > But why? That __future__ import is supposed to make > absolute > imports the default, so why is "import thetest" importing > thetest.py instead of the package called thetest? The absolute > import should make it look in sys.path first and not try to import > from the script directory, right? > > If I change the outer directory name and change the code > in > thetest.py to match, it works fine. But I shouldn't have to do > this. How can I get relative imports to work correctly when > running a script whose filename is the same as that of the > directory (and thus the package) in which it resides? After a bit more googling I discovered the answer here: http://stackoverflow.com/questions/1959188/absolute-import-failing-in- subpackage-that-shadows-a-stdlib-package-name The deal is that sys.path by default has the empty string as the first element, which tells Python to look first in the directory of the script being executed. This is unfortunate, but can worked around this way: import sys sys.path = sys.path[1:] + [''] (That is, move the current directory to the end of the search path instead of the beginning.) -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown -- http://mail.python.org/mailman/listinfo/python-list
Relative import from script with same name as package
I'm using Python 2.6.5. I have a directory structure like this: thetest/ __init__.py thetest.py theother.py __init__.py is an empty file. theother.py contains a function foo(). The package is accessible from sys.path, so that if I open the interpreter and do "import thetest" or "from thetest import thetest" or "import thetest.thetest", it works fine. Inside thetest.py I have code like this: ### from __future__ import absolute_import if __name__ == "__main__" and __package__ is None: import thetest __package__ = "thetest" from .theother import foo ### Note that I need the "import thetest" line to avoid a "parent module not loaded" error, as described here: http://stackoverflow.com/questions/2943847/nightmare-with-relative- imports-how-does-pep-366-work If I run foo.py directly, I receive a traceback like this: Traceback (most recent call last): File "C:\...\thetest\thetest.py", line 4, in import thetest File "C:\...\thetest\thetest.py", line 11, in from .theother import foo ValueError: Attempted relative import in non-package It appears that Python is reading "import thetest" as importing thetest.py (the same file that is currently being run). When it tries to run that file a second time, the relative import fails. But why? That __future__ import is supposed to make absolute imports the default, so why is "import thetest" importing thetest.py instead of the package called thetest? The absolute import should make it look in sys.path first and not try to import from the script directory, right? If I change the outer directory name and change the code in thetest.py to match, it works fine. But I shouldn't have to do this. How can I get relative imports to work correctly when running a script whose filename is the same as that of the directory (and thus the package) in which it resides? -- --OKB (not okblacke) Brendan Barnwell "Do not follow where the path may lead. Go, instead, where there is no path, and leave a trail." --author unknown -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I convert String into Date object
BTW, here is the Python version I'm using. Will this make a difference with the solutions you guys provided? Python 2.6.1 (r261:67515, Jun 24 2010, 21:47:49) [GCC 4.2.1 (Apple Inc. build 5646)] on darwin Also, what editor do you guys use? There are so many to chose from. On Aug 13, 4:11 pm, Rafael Durán Castañeda wrote: > You can use datetime objects: > > >>> dt1 = datetime.datetime.strptime('07/27/2011',"%m/%d/%Y") > >>> dt2 =datetime.datetime.strptime('07/28/2011',"%m/%d/%Y") > >>> dt1 == dt2 > False > >>> dt1 > dt2 > False > >>> dt1 < dt2 > True > >>> dt1 - dt2 > datetime.timedelta(-1) > > On 13/08/11 21:26, MrPink wrote: > > > > > > > > > I have file of records delimited by spaces. > > I need to import the date string and convert them into date datatypes. > > > '07/27/2011' 'Event 1 Description' > > '07/28/2011' 'Event 2 Description' > > '07/29/2011' 'Event 3 Description' > > > I just discovered that my oDate is not an object, but a structure and > > not a date datatype. > > I'm stumped. Is there a way to convert a string into a date datatype > > for comparisons, equality, etc? > > > Thanks, > > > On Aug 13, 3:14 pm, MrPink wrote: > >> Is this the correct way to convert a String into a Date? > >> I only have dates and no time. > > >> import time, datetime > > >> oDate = time.strptime('07/27/2011', '%m/%d/%Y') > >> print oDate > > >> Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I convert String into Date object
MrPink wrote: > I have file of records delimited by spaces. > I need to import the date string and convert them into date datatypes. > > '07/27/2011' 'Event 1 Description' > '07/28/2011' 'Event 2 Description' > '07/29/2011' 'Event 3 Description' > > I just discovered that my oDate is not an object, but a structure and > not a date datatype. > I'm stumped. Is there a way to convert a string into a date datatype > for comparisons, equality, etc? > > Thanks, > > On Aug 13, 3:14 pm, MrPink wrote: >> Is this the correct way to convert a String into a Date? >> I only have dates and no time. >> >> import time, datetime That looks like a fifty-percent chance to try the "wrong" module ;) >> oDate = time.strptime('07/27/2011', '%m/%d/%Y') >> print oDate >>> import datetime as dt >>> d = dt.date.strptime("07/27/2011", "%m/%d/%Y") Traceback (most recent call last): File "", line 1, in AttributeError: type object 'datetime.date' has no attribute 'strptime' So you cannot construct a date from a date string either. One more time: >>> d = dt.datetime.strptime("07/27/2011", "%m/%d/%Y") >>> d datetime.datetime(2011, 7, 27, 0, 0) >>> d.date() datetime.date(2011, 7, 27) $ cat csv_dates.csv '07/27/2011' 'Event 1 Description' '07/28/2011' 'Event 2 Description' '07/29/2011' 'Event 3 Description' $ cat csv_dates.py import datetime import csv def rows(instream): for row in csv.reader(instream, delimiter=" ", quotechar="'"): row[0] = datetime.datetime.strptime(row[0], '%m/%d/%Y').date() yield row if __name__ == "__main__": import sys filename = sys.argv[1] with open(filename, "rb") as instream: for row in rows(instream): print row $ python csv_dates.py csv_dates.csv [datetime.date(2011, 7, 27), 'Event 1 Description'] [datetime.date(2011, 7, 28), 'Event 2 Description'] [datetime.date(2011, 7, 29), 'Event 3 Description'] -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I convert String into Date object
You can use datetime objects: >>> dt1 = datetime.datetime.strptime('07/27/2011',"%m/%d/%Y") >>> dt2 =datetime.datetime.strptime('07/28/2011',"%m/%d/%Y") >>> dt1 == dt2 False >>> dt1 > dt2 False >>> dt1 < dt2 True >>> dt1 - dt2 datetime.timedelta(-1) On 13/08/11 21:26, MrPink wrote: I have file of records delimited by spaces. I need to import the date string and convert them into date datatypes. '07/27/2011' 'Event 1 Description' '07/28/2011' 'Event 2 Description' '07/29/2011' 'Event 3 Description' I just discovered that my oDate is not an object, but a structure and not a date datatype. I'm stumped. Is there a way to convert a string into a date datatype for comparisons, equality, etc? Thanks, On Aug 13, 3:14 pm, MrPink wrote: Is this the correct way to convert a String into a Date? I only have dates and no time. import time, datetime oDate = time.strptime('07/27/2011', '%m/%d/%Y') print oDate Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I convert String into Date object
On Sat, Aug 13, 2011 at 12:14 PM, MrPink wrote: > Is this the correct way to convert a String into a Date? > I only have dates and no time. > > import time, datetime > > oDate = time.strptime('07/27/2011', '%m/%d/%Y') > print oDate from datetime import datetime the_date = datetime.strptime('07/27/2011', '%m/%d/%Y').date() Cheers, Chris -- http://mail.python.org/mailman/listinfo/python-list
Re: How do I convert String into Date object
I have file of records delimited by spaces. I need to import the date string and convert them into date datatypes. '07/27/2011' 'Event 1 Description' '07/28/2011' 'Event 2 Description' '07/29/2011' 'Event 3 Description' I just discovered that my oDate is not an object, but a structure and not a date datatype. I'm stumped. Is there a way to convert a string into a date datatype for comparisons, equality, etc? Thanks, On Aug 13, 3:14 pm, MrPink wrote: > Is this the correct way to convert a String into a Date? > I only have dates and no time. > > import time, datetime > > oDate = time.strptime('07/27/2011', '%m/%d/%Y') > print oDate > > Thanks, -- http://mail.python.org/mailman/listinfo/python-list
How do I convert String into Date object
Is this the correct way to convert a String into a Date? I only have dates and no time. import time, datetime oDate = time.strptime('07/27/2011', '%m/%d/%Y') print oDate Thanks, -- http://mail.python.org/mailman/listinfo/python-list
Re: Dialog boxes in curses
Thanks all for your suggestions, I'll look into them. See you. -- F. Delente -- http://mail.python.org/mailman/listinfo/python-list
Re: Dialog boxes in curses
* f...@slick.airforce-one.org (13 Aug 2011 15:21:01 GMT) > I want to have dialog boxes (a message with Yes/No/Cancel options, > possibly with keyboard accels) in python + curses. Use Python Dialog[1] which is basically a wrapper for dialog boxes around ncurses. Thorsten [1] http://pythondialog.sourceforge.net/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Dialog boxes in curses
On Sat, Aug 13, 2011 at 4:37 PM, Irmen de Jong wrote: > On 13-8-2011 17:21, f...@slick.airforce-one.org wrote: >> Hello. >> >> I've googled for hints but I didn't find anything, I hope it's not an >> RTFM question :^) >> >> I want to have dialog boxes (a message with Yes/No/Cancel options, >> possibly with keyboard accels) in python + curses. >> >> Does anyone have a pointer to docs about this? >> >> Thanks! Or have a look at code.google.com/p/npyscreen Nicholas -- http://mail.python.org/mailman/listinfo/python-list
Re: Dialog boxes in curses
On 13-8-2011 17:21, f...@slick.airforce-one.org wrote: > Hello. > > I've googled for hints but I didn't find anything, I hope it's not an > RTFM question :^) > > I want to have dialog boxes (a message with Yes/No/Cancel options, > possibly with keyboard accels) in python + curses. > > Does anyone have a pointer to docs about this? > > Thanks! > Have you considered using Urwid instead? http://excess.org/urwid/ Irmen -- http://mail.python.org/mailman/listinfo/python-list
Dialog boxes in curses
Hello. I've googled for hints but I didn't find anything, I hope it's not an RTFM question :^) I want to have dialog boxes (a message with Yes/No/Cancel options, possibly with keyboard accels) in python + curses. Does anyone have a pointer to docs about this? Thanks! -- F. Delente -- http://mail.python.org/mailman/listinfo/python-list
Re: Java is killing me! (AKA: Java for Pythonheads?)
On Aug 12, 1:35 pm, MRAB wrote: > On 12/08/2011 18:02, kj wrote: > > > > > > > > > > > *Please* forgive me for asking a Java question in a Python forum. > > My only excuse for this no-no is that a Python forum is more likely > > than a Java one to have among its readers those who have had to > > deal with the same problems I'm wrestling with. > > > Due to my job, I have to port some Python code to Java, and write > > tests for the ported code. (Yes, I've considered finding myself > > another job, but this is not an option in the immediate future.) > > > What's giving me the hardest time is that the original Python code > > uses a lot of functions with optional arguments (as is natural to > > do in Python). > > > As far as I can tell (admittedly I'm no Java expert, and have not > > programmed in it since 2001), to implement a Java method with n > > optional arguments, one needs at least 2**n method definitions. > > Even if all but one of these definitions are simple wrappers that > > call the one that does all the work, it's still a lot of code to > > wade through, for nothing. > > > That's bad enough, but even worse is writing the unit tests for > > the resulting mountain of fluffCode. I find myself writing test > > classes whose constructors also require 2**n definitions, one for > > each form of the function to be tested... > > > I ask myself, how does the journeyman Python programmer cope with > > such nonsense? > > > For the sake of concreteness, consider the following run-of-the-mill > > Python function of 3 arguments (the first argument, xs, is expected > > to be either a float or a sequence of floats; the second and third > > arguments, an int and a float, are optional): > > > def quant(xs, nlevels=MAXN, xlim=MAXX): > > if not hasattr(xs, '__iter__'): > > return spam((xs,), n, xlim)[0] > > > if _bad_quant_args(xs, nlevels, xlim): > > raise TypeError("invalid arguments") > > > retval = [] > > for x in xs: > > # ... > > # elaborate acrobatics that set y > > # ... > > retval.append(y) > > > return retval > > > My Java implementation of it already requires at least 8 method > > definitions, with signatures: > > [snip] > > I would declare: > > short[] quant (float[], int , float) > short quant (Float , Integer, Float) > > and see how it goes. > > "float" and "int" should be boxed to "Float" and "Integer" > automatically. > > If the second and third arguments are frequently the default, then I > would also declare: > > short[] quant (float[]) > short quant (Float ) This seems to be a very good solution but I would replace basic types with wrappers short[] quant (float[], Integer, Float) short quant (Float , Integer, Float) When you implement those two methods (where you need to check if Integer, Float are not null) then you can define two more methods: short[] quant (float[]) { return quant (float[], null, null); } short quant (float) { return quant (float, null, null); } That gives you 2 methods for unit testing. -- http://mail.python.org/mailman/listinfo/python-list
Re: thread and process
On 01/-10/-28163 02:59 PM, 守株待兔 wrote: please see my code: import os import threading print threading.currentThread() print "i am parent ",os.getpid() ret = os.fork() print "i am here",os.getpid() print threading.currentThread() if ret == 0: print threading.currentThread() else: os.wait() print threading.currentThread() print "i am runing,who am i? ",os.getpid(),threading.currentThread() the output is: <_MainThread(MainThread, started -1216477504)> i am parent 13495 i am here 13495 <_MainThread(MainThread, started -1216477504)> i am here 13496 <_MainThread(MainThread, started -1216477504)> <_MainThread(MainThread, started -1216477504)> i am runing,who am i? 13496<_MainThread(MainThread, started -1216477504)> <_MainThread(MainThread, started -1216477504)> i am runing,who am i? 13495<_MainThread(MainThread, started -1216477504)> it is so strange that two different processes use one mainthread!! Why would you figure that it's the same thread? You're just looking at the ID of the thread object in each process, and ID's have no promise of being unique between different processes, nor between multiple runs of the same program. In CPython, the id is actually an address, and each process has its own address space. The addresses happen to be the same because the main thread was created before you forked. DaveA -- http://mail.python.org/mailman/listinfo/python-list
Re: thread and process
On Saturday, August 13, 2011 2:09:55 AM UTC-7, 守株待兔 wrote: > please see my code: > import os > import threading > print threading.currentThread() > print "i am parent ",os.getpid() > ret = os.fork() > print "i am here",os.getpid() > print threading.currentThread() > if ret == 0: > print threading.currentThread() > else: > os.wait() > print threading.currentThread() > > > print "i am runing,who am i? > ",os.getpid(),threading.currentThread() > > the output is: > <_MainThread(MainThread, started -1216477504)> > i am parent 13495 > i am here 13495 > <_MainThread(MainThread, started -1216477504)> > i am here 13496 > <_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i? 13496 <_MainThread(MainThread, started > -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i? 13495 <_MainThread(MainThread, started > -1216477504)> > it is so strange that two different processes use one mainthread!! They don't use one main thread; it's just that each process's main thread has the same name. Which makes sense: when you fork a process all the data in the process has to remain valid in both parent and child, so any pointers would have to have the same value (and the -1216477504 happens to be the value of that pointer cast to an int). Carl Banks -- http://mail.python.org/mailman/listinfo/python-list
Re: generate and send mail with python: tutorial
On Aug 13, 3:00 am, Ben Finney wrote: > Ben Finney writes: > > What is the process if the OP, or someone to whom the OP delegates > > authority, wants to [contribute their work to the Python > > documentation]? > > The answer is partly at http://docs.python.org/documenting/>: > > If you’re interested in contributing to Python’s documentation […] > Send an e-mail to d...@python.org or open an issue on the tracker. > > One should, before doing so, follow the above document on the > documentation style conventions for Python. I'm using python for long now, and just discovered these HowTo today :- ( I don't thing rewriting these articles into another format will improve the "message". I will not rewrite them. You are free to do it, just keep my name as the original author. I have no other original source than the HTML one you can have on my blog. I appreciate your interest for my work. I think to put all the sources together to create a library. I thing about the name of pyezmail for "python easy mail". Any comment ? Regards > > -- > \ “Contentment is a pearl of great price, and whosoever procures | > `\ it at the expense of ten thousand desires makes a wise and | > _o__) happy purchase.” —J. Balguy | > Ben Finney -- http://mail.python.org/mailman/listinfo/python-list
Re: thread and process
On Aug 13, 11:09 am, "守株待兔" <1248283...@qq.com> wrote: > please see my code: > import os > import threading > print threading.currentThread() > print "i am parent ",os.getpid() > ret = os.fork() > print "i am here",os.getpid() > print threading.currentThread() > if ret == 0: > print threading.currentThread() > else: > os.wait() > print threading.currentThread() > > print "i am runing,who am i? ",os.getpid(),threading.currentThread() > > the output is: > <_MainThread(MainThread, started -1216477504)> > i am parent 13495 > i am here 13495 > <_MainThread(MainThread, started -1216477504)> > i am here 13496 > <_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i? 13496 <_MainThread(MainThread, started -1216477504)> > <_MainThread(MainThread, started -1216477504)> > i am runing,who am i? 13495 <_MainThread(MainThread, started -1216477504)> > it is so strange that two different processes use one mainthread!! You should not mix thread and fork. Some hint : You put your "import threading" before your fork(), then data initialized by the import are the same in the two process then it display the same, this is like a=-1216477504 os.fork() print a second I thing -1216477504 has no meaning, this is not a system thread ID but just an ID generated by python I think they must be unique inside a process but not cross process. Then 2 process can have the same python thread ID. If you have to mix thread and fork try to find some hints from Internet. Something like don't fork a process that already has tread(), or try to keep all your threads inside the same process ... Regards -- http://mail.python.org/mailman/listinfo/python-list
thread and process
please see my code: import os import threading print threading.currentThread() print "i am parent ",os.getpid() ret = os.fork() print "i am here",os.getpid() print threading.currentThread() if ret == 0: print threading.currentThread() else: os.wait() print threading.currentThread() print "i am runing,who am i? ",os.getpid(),threading.currentThread() the output is: <_MainThread(MainThread, started -1216477504)> i am parent 13495 i am here 13495 <_MainThread(MainThread, started -1216477504)> i am here 13496 <_MainThread(MainThread, started -1216477504)> <_MainThread(MainThread, started -1216477504)> i am runing,who am i? 13496 <_MainThread(MainThread, started -1216477504)> <_MainThread(MainThread, started -1216477504)> i am runing,who am i? 13495 <_MainThread(MainThread, started -1216477504)> it is so strange that two different processes use one mainthread!!-- http://mail.python.org/mailman/listinfo/python-list