Re: DBF records API
On 02/06/2012 06:16, Ethan Furman wrote: Tim Chase wrote: On 06/01/12 19:05, Jon Clements wrote: On 01/06/12 23:13, Tim Chase wrote: dbf.scatter_fields *always* trump and refer to the method. I did think about *trumping* one way or the other, but both *ugh*. For the record, it sounded like the OP wanted to be able to use the dot-notation for accessing fields by name, and I think it's a pretty non-pythonic way to do it. I'd much rather just stick to purely using __getitem__ for the fields and attributes/methods for non-fields. It can't be *that* non-Pythonic -- we now have namedtuples which pretty much behave just like my record class (although its indexes are only numbers, not strings as well). namedtuple prefixes its methods with "_", so you could just have: record.name and: record._deleted -- http://mail.python.org/mailman/listinfo/python-list
Re: DBF records API
On 06/02/12 00:16, Ethan Furman wrote: > Tim Chase wrote: >> On 06/01/12 19:05, Jon Clements wrote: >>> On 01/06/12 23:13, Tim Chase wrote: dbf.scatter_fields *always* trump and refer to the method. >>> I did think about *trumping* one way or the other, but both *ugh*. >> >> For the record, it sounded like the OP wanted to be able to use the >> dot-notation for accessing fields by name, and I think it's a pretty >> non-pythonic way to do it. I'd much rather just stick to purely >> using __getitem__ for the fields and attributes/methods for non-fields. > > It can't be *that* non-Pythonic -- we now have namedtuples which pretty > much behave just like my record class (although its indexes are only > numbers, not strings as well). Right, but the contents of the named-tuple are usually static in relation to the code itself, rather than dependent on external factors (such as user-supplied DBF files). In addition, I believe namedtuple has methods prefixed by an underscore to stave off clashing names. -tkc -- http://mail.python.org/mailman/listinfo/python-list
Re: Tkinter deadlock on graceful exit
On Jun/01, Matteo Landi wrote: > On Thu, May 31, 2012 at 3:02 PM, Matteo Landi wrote: > > On Thu, May 31, 2012 at 3:42 AM, Terry Reedy wrote: > >> On 5/30/2012 6:19 PM, Matteo Landi wrote: > >>> > >>> On May/28, Matteo Landi wrote: > > Hi list, > recently I started to work on an application [1] which makes use of the > Tkinter > module to handle interaction with the user. Simply put, the app is a > text > widget displaying a file filtered by given criteria, with a handy feature > that > the window is raised each time a new line is added to the widget. > > The application mainly consists of three threads: the first one, the > file > processor, reads the file, filters the lines of interest, and pushes them > into > a shared queue (henceforth `lines_queue`); the second one, the > gui_updater, > pops elements from `lines_queue`, and schedule GUI updates using the > `after_idle` method of the Tkinter module; finally the last one, the > worker > spawner, receives commands by the gui (by means of a shared queue, > `filters_queue`), and drives the application, terminating or spawning new > threads. > > For example, let's see what happens when you start the application, fill > the > filter entry and press Enter button: > 1 the associated even handler is scheduled (we should be inside the > Tkinter > mainloop thread), and the filter is pushed into `filters_queue`; > 2 the worker spawner receives the new filter, terminate a possibly > running > working thread, and once done, create a new file processor; > 3 the file processor actually processes the file and fills the > `lines_queue` > with the lines matching given filter; > 4 the gui updater schedules GUI updates as soon as items are pushed into > `lines_queue` > 5 Tkinter mainloop thread updates the gui when idle > > What happens when the main window is closed? Here is how I implemented > the > graceful shutdown of the app: > 1 a quit event is scheduled and a _special_ message is pushed into both > `filter_queue` and `lines_queue` > 2 the gui updater threads receives the _special_ message, and terminates > 3 the worker spawner receives the message, terminates the working thread > and > interrupts her execution. > 4 Tk.quit() is called after the quit event handler, and we finally quit > the > mainloop > > Honestly speaking, I see no issues with the algorithm presented above; > however, > if I close the window in the middle of updates of the text widget, the > applications hangs indefinitely. On the other hand, everything works as > expected if I close the app when the file processor, for example, is > waiting for > new content to filter. > > I put some logging messages to analyze the deadlock (?!), and noticed > that both > the worker spawner and the file processor are terminated correctly. The > only > thread still active for some strange reasons, is the gui updater. > > Do you see anything wrong with the description presented above? Please > say so, > because I can't figure it out! > >> > >> > >> Since no-one else answered, I will ask some questions based on little > >> tkinter experience, no thread experience, and a bit of python-list reading. > >> > >> 1. Are you only using tkinter in one thread? (It seems like so from the > >> above)? > > > > Yes, provided that `after_idle` queues a job for the gui thread > > > >> > >> 2. Is root.destroy getting called, as in 24.1.2.2. A Simple Hello World > >> Program in the most recent docs? (I specify 'most recent' because that > >> example has been recently revised because the previous version sometimes > >> left tkinter hanging for one of the code paths, perhaps similar to what you > >> describe. > > > > No, I'm not calling the destroy method of the main window but, why > > that only happens while doing gui updates? > > > >> > >> 3. Have you tried making the gui thread the master thread? (I somehow > >> expect > >> that the gui thread should be the last to shut down.) > > > > No but, same question as above. > > > > I'm not home right now, so I will try those solutions as soon as > > possible. Thanks. > > > > > > Cheers, > > Matteo > > > >> > >> -- > >> Terry Jan Reedy > >> > >> -- > >> http://mail.python.org/mailman/listinfo/python-list > > > > > > > > -- > > http://www.matteolandi.net/ > > Doing further investigation, I found this post [1] dated 2005, which > probably explains why I'm gatting this strange deadlock. > > Quoting the linked article: > > All Tkinter access must be from the main thread (or, more precisely, > the thread that called mainloop). Violating this is likely to cause > nasty and mysterious symptoms such as freezes or core dumps. Yes th
how to typecast a ctypes pointer to another one
Hi,
I have a result from a call to a ctypes function of type c_void_p.
Now I'd like to convert it to a pointer to one of the structures, that I
defined.
result = library.c_function(params)
class MyStruct(ctypes.Structure):
_fields_ = [
('fourbytes', ctypes.c_char * 4)
]
I know I could (prior to calling) specify what datatype the function
should return)
However as depending on some other conditions I have to interpret the
return value either as pointer to one or another data type or another one.
Id' like to perform the casting after having received the value.
Thanks in advance for any pointers.
--
http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7.3, C++ embed memory leak?
Qi writes: > Hi guys, > > Is there any known memory leak problems, when embed Python 2.7.3 > in C++? > I Googled but only found some old posts. > > I tried to only call Py_Initialize() and Py_Finalize(), nothing else > between those functions, Valgrind still reports memory leaks > on Ubuntu? > > Is that a know problem? Did Python 3.x solve it? > > I want some confirmation. Python does some special things that confuse valgrind. Don't bother. http://svn.python.org/projects/python/trunk/Misc/README.valgrind Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: ctypes callback with char array
ohlfsen writes: > Hello. > > Hoping that someone can shed some light on a tiny challenge of mine. > > Through ctypes I'm calling a c DLL which requires me to implement a callback > in Python/ctypes. > > The signature of the callback is something like > > void foo(int NoOfElements, char Elements[][100]) > > How do I possible implement/process "char Elements[][100]" in Python/ctypes > code? I'd try it like this: $ python Python 2.7 (r27:82500, May 2 2011, 22:50:11) [GCC 4.2.1 (Apple Inc. build 5664)] on darwin Type "help", "copyright", "credits" or "license" for more information. oWelcome to rlcompleter2 0.98 for nice experiences hit multiple times >>> from ctypes import * >>> callback_type = CFUNCTYPE(None, c_int, POINTER(c_char_p)) >>> def my_callback(int, elements): ... pass ... >>> c_callback = callback_type(my_callback) >>> c_callback No need to know that it's a pointer to char[100] pointers - you can cast that if you want to. Diez -- http://mail.python.org/mailman/listinfo/python-list
Re: Python 2.7.3, C++ embed memory leak?
On 2012-6-2 18:53, Diez B. Roggisch wrote: Python does some special things that confuse valgrind. Don't bother. http://svn.python.org/projects/python/trunk/Misc/README.valgrind Thanks for the link. It clears a lot of my confusing, such as uninitialized reading... -- WQ -- http://mail.python.org/mailman/listinfo/python-list
WHAT DO MUSLIMS THINK ABOUT JESUS ?????????
WHAT DO MUSLIMS THINK ABOUT JESUS? I know that my article is not related to this group ,but it might be useful. PLEASE read it What do Muslims think about Jesus? Muslims respect and revere Jesus (SAW) and await his Second Coming. They consider him one of the greatest of God’s messengers to mankind. A Muslim never refers to him simply as ‘Jesus’, but always adds the phrase ‘upon him be peace’. The Quran confirms his virgin birth (a chapter of the Quran is entitled ‘Mary’), and Mary is considered the purest woman in all creation. The Quran describes the Annunciation as follows: ‘Behold!’ the Angel said, ‘God has chosen you, and purified you, and chosen you above the women of all nations. O Mary, God gives you good news of a word from Him, whose name shall be the Messiah, Jesus son of Mary, honored in this world and the Hereafter, and one of those brought near to God. He shall speak to the people from his cradle and in maturity, and shall be of the righteous.’ She said: ‘O my Lord! How shall I have a son when no man has touched me?’ He said: ‘Even so; God creates what He will. When He decrees a thing He says to it, "Be!" and it is.’ (Quran, 3.42-7) Jesus (SAW) was born miraculously through the same power which had brought Adam (SAW) into being without a father: Truly, the likeness of Jesus with God is as the likeness of Adam. He created him of dust, and then said to him, ‘Be!’ and he was. (3.59) During his prophetic mission Jesus (SAW) performed many miracles. The Quran tells us that he said: ‘I have come to you with a sign from your Lord: I make for you out of clay, as it were, the figure of a bird, and breathe into it and it becomes a bird by God’s leave. And I heal the blind, and the lepers, and I raise the dead by God’s leave.’ (3.49) Neither Muhammad (SAW) nor Jesus (SAW) came to change the basic doctrine of the belief in One God, brought by earlier prophets, but to confirm and renew it. In the Quran Jesus (SAW) is reported as saying that he came: ‘To attest the law which was before me. And to make lawful to you paff of what was forbidden you; I have come to you with a sign from your Lord, so fear God and obey Me.’ (3:5O) The Prophet Muhammad (SAW) said: ‘Whoever believes there is no god but God, alone without partner, that Muhammad (SAW) is His messenger, that Jesus is the servant and messenger of God, His word breathed into Mary and a spirit emanating from Him, and that Paradise and Hell are true, shall be received by God into Heaven.’ (Hadith from Bukhari) —- For more information about Islam http://www.islam-guide.com http://www.islamhouse.com/s/9661 http://www.thisistruth.org http://www.quran-m.com/firas/en1 http://kaheel7.com/eng http://www.knowmuhammad.com http://www.rasoulallah.net/v2/index.aspx?lang=e http://imanway1.com/eng http://www.todayislam.com http://www.thekeytoislam.com http://www.islamland.com http://www.discoverislam.com http://www.thetruereligion.org http://www.beconvinced.com http://islamtomorrow.com http://www.quranforall.org http://www.quranexplorer.com/quran http://www.prophetmuhammed.org http://chatislamonline.org/en/ -- http://mail.python.org/mailman/listinfo/python-list
Re: Smallest/cheapest possible Python platform?
There is a 3rd party programmer for the LaunchPad that lets you program it in Python, but I forgot what they were called. It has an m somewhere in it and it's 3 letters. I saw it at MakerFaire. I got their card, but lost it. If I remember the name, I'll post it here. -- http://mail.python.org/mailman/listinfo/python-list
Re: Smallest/cheapest possible Python platform?
On 02/06/2012 21:47, boj wrote: There is a 3rd party programmer for the LaunchPad that lets you program it in Python, but I forgot what they were called. It has an m somewhere in it and it's 3 letters. I saw it at MakerFaire. I got their card, but lost it. If I remember the name, I'll post it here. Putting "LaunchPad", "Python" and "MakerFaire" into Google, plus the "It has an m somewhere in it and it's 3 letters", quickly led me to: http://www.mpyprojects.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Smallest/cheapest possible Python platform?
On Sun, Jun 3, 2012 at 7:18 AM, MRAB wrote: > Putting "LaunchPad", "Python" and "MakerFaire" into Google, plus the > "It has an m somewhere in it and it's 3 letters", quickly led me to: > > http://www.mpyprojects.com > -- Heh, Google's awesome :) I was just thinking "Hm, three letters with an M? That gives you about two thousand possibilities, not too many to brute-force..." That looks rather cool, but I'm minorly concerned by a heading in http://www.mpyprojects.com/mpy-language/ that hints that the mpy language isn't Python exactly, but doesn't have a link to the actual page on which the differences are detailed. It might be trivial differences like the lack of most of the standard library, but then again, it might be more than that. ChrisA -- http://mail.python.org/mailman/listinfo/python-list
Re: Smallest/cheapest possible Python platform?
On 02/06/2012 22:25, Chris Angelico wrote: On Sun, Jun 3, 2012 at 7:18 AM, MRAB wrote: Putting "LaunchPad", "Python" and "MakerFaire" into Google, plus the "It has an m somewhere in it and it's 3 letters", quickly led me to: http://www.mpyprojects.com -- Heh, Google's awesome :) I was just thinking "Hm, three letters with an M? That gives you about two thousand possibilities, not too many to brute-force..." Well, if it's something to do with Python, there wouldn't been a good chance that 2 of the letters would be "Py". That reduces the number of possibilities somewhat! :-) That looks rather cool, but I'm minorly concerned by a heading in http://www.mpyprojects.com/mpy-language/ that hints that the mpy language isn't Python exactly, but doesn't have a link to the actual page on which the differences are detailed. It might be trivial differences like the lack of most of the standard library, but then again, it might be more than that. Look at the "Software" page: """We use the mpy language to program the MSP430 microcontroller. MPY is short for Microcontroller PYthon. mpy is based on the Python computer language. In fact to keep things simple it is only a small subset of the Python language.""" -- http://mail.python.org/mailman/listinfo/python-list
Re: Smallest/cheapest possible Python platform?
On Sun, Jun 3, 2012 at 8:09 AM, MRAB wrote: > Look at the "Software" page: > > """We use the mpy language to program the MSP430 microcontroller. MPY is > short for Microcontroller PYthon. mpy is based on the Python computer > language. In fact to keep things simple it is only a small subset of the > Python language.""" Ah, yes I missed that. Seems it's Python-like language implemented in Python, which is I think a smart way to do it (assuming that this code isn't going to have trust issues). ChrisA -- http://mail.python.org/mailman/listinfo/python-list
