Re: do people really complain about significant whitespace?

2006-08-10 Thread H J van Rooyen

Dennis Lee Bieber [EMAIL PROTECTED] wrote:

| On 8 Aug 2006 04:59:34 -0700, [EMAIL PROTECTED] declaimed the
| following in comp.lang.python:
|
| 
|  Some of it may be a reaction from old-timers who remember FORTRAN,
|  where (if memory serves), code had to start in column 16 and code
|  continutations had to be an asterik in column 72 (it's been many years
|  since I've done any work in FORTRAN, but you get the idea)
| 
| Comment C in column 1
| (often extended to accept OS JCL markers too)
| Label numeric in 1-5
| Continuation anything in column 6
| (DEC, if using tab indents would take tab)
| Statement column 7-72
| Sequence/ID column 73-80
|
| I forget what COBOL used, but it had a few fields of its own.

The COBOL I used (NCR Century, Burroughs, some little IBM) was not fussy - the
only thing was that like in assembler, you had to start a lable  (that is a
symbolic name for an address) in the first column...

And you *had* to end what Python calls a suite with a fullstop - many hours
spent looking for weird bugs..

The breaking of the link between a lable or name and a memory address of
something is what I think most newcomers to Python find horribly confusing...

- Hendrik



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: testing array of logicals

2006-08-07 Thread H J van Rooyen

 Janto Dreijer [EMAIL PROTECTED] wrote:


|
| Janto Dreijer wrote:
|  John Henry wrote:
|   Simon Forman wrote:
|
| False not in logflags
|
|   
|Or, if your values aren't already bools
|   
|False not in (bool(n) for n in logflags)
|  
|   Very intriguing use of not in...
| 
|  Is there a reason why you didn't write
|   True in (bool(n) for n in logflags)
|
| slaps forehead doh! Never mind.
|

 *lol* - don't feel bad about this - real programmers make this mistake with a
varying frequency -
From once every six days or so if you are no good, to once in a lifetime if
you are brilliant, and never only if you are a genius...

First time it bit me I was an apprentice writing in Cobol.

- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-07 Thread H J van Rooyen

Dennis Lee Bieber [EMAIL PROTECTED] wrote:


| On Sat, 5 Aug 2006 11:20:59 +0200, H J van Rooyen
| [EMAIL PROTECTED] declaimed the following in comp.lang.python:
|
| 
|  no such luck - reality will probably be Linux for server, and a horrible mix
of
|  windoze machines on the client side - from 95 through 98 and 2000 to XP...
will
|  have to get SAMBA running at least - and it could be tricky with some of the
|  older hardware/software around - but that is another fight, that I would
have to
|  solve anyway.
| 
| Well, other than the security differences -- which may not apply
| when the clients are mounting a share, only when the define a shareable
| partition -- I think the Windows side may be similar all the way
| through.
|
|  This is more the kind of thing I had in mind - but I was not thinking in
terms
|  of having the redirecting done by the OS and network file sharing - stupid I
|  suppose...
| 
|
| Not really -- if one first is thinking in terms of internet, which
| means unsecured global operations, instead of an internal-only, behind
| firewall, system.

*grin* you are being too kind - I was at no stage thinking internet...

|
|  | add the share to the pythonpath (hence you want a uniform system
|  | configuration so each machine mounts the share on the same name).
|  |
| 
|  I will have to think of a solution to this *shudders*  - config files,
maybe...
| 
| I think Windows can be set to reconnect on start-up, but it may be
| better just to add a BAT file to the client machines' system start-up
| directory containing the command line that mounts such a share.
|
|

This is a good idea - thanks

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-07 Thread H J van Rooyen

Bruno Desthuilliers [EMAIL PROTECTED]


H J van Rooyen a écrit :
  Dennis Lee Bieber [EMAIL PROTECTED] wrote:

(snip)
 | If you go the web application route, each login would use a cookie
 | to control session, so the application server can determine what
 | functions to present to the user. You might even be able to use
 | something like Plone to build the application server; it already has
 | capability to present different views based upon login.

 Know squat about Plone - another thing to add to my list of reading *sigh*

Well, actually, I would not bother too much reading about Plone here -
Plone is (fairly complex and somewhat slow) CMS built on top of Zope,
which is itself a web application server that's not easy to get started
with and is (IMHO) definitively much more suited to CMS than to
accounting apps.

*deletes the reference to Plone from the little text file*

- Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-05 Thread H J van Rooyen

Dennis Lee Bieber [EMAIL PROTECTED] wrote:

8--

| There may be something in-between. IFF this is to be used strictly
| on an internal LAN with uniform architecture (all Linux or all WinXP)
| for the client machines. You'd have to set up something so a reboot

no such luck - reality will probably be Linux for server, and a horrible mix of
windoze machines on the client side - from 95 through 98 and 2000 to XP... will
have to get SAMBA running at least - and it could be tricky with some of the
older hardware/software around - but that is another fight, that I would have to
solve anyway.

| remounts correctly but... (In WinXP terms) Create a read-only share on
| a file server. The file server will contain the Python modules that make
| up the client. The client start-up still uses a login to obtain a
| privilege map, which controls the menu/form access. However, rather than
| having to push the modules to each client, you delay the module import
| until the form it controls is invoked. The start-up module would have to

This is more the kind of thing I had in mind - but I was not thinking in terms
of having the redirecting done by the OS and network file sharing - stupid I
suppose...

| add the share to the pythonpath (hence you want a uniform system
| configuration so each machine mounts the share on the same name).
|

I will have to think of a solution to this *shudders*  - config files, maybe...


| It's still an all-in-one client, but you don't have to install
| anything on the user machines (except the share and a shortcut to the
| start-up module).
|
| For Linux, this would be an NFS mount.

*nods* Thanks Dennis  - I am busy drinking out of the Pyro fire hose at the
moment - and the stuff I have seen so far looks bloody awesome - you do some
little bit of magic setup - and hey - you have a name server that you can query
and then you can remotely execute a method on a remote object just as if its
here in your machine, and you get the returns just like you would if the object
were local to the machine your Python script is running in...

And they have made a sort of mirror of the name server thingy so that you can
fall back to a non broken one and resync when things go wrong go wrong go
wrong...

As a low level johnny this sort of functionality impresses the hell out of me -
when I think of the time I have spent struggling to get a few small tightly
coupled machines to work together in a primitive way - my mind boggles at this -
you could create awesome capability by having multiple copies of objects hanging
around in different machines - and simply keep track of how much they are loaded
by monitoring their input queues - and make more instances as you need them as
loading gets higher...  The only bottleneck is the LAN's capacity to move the
data around - but in most WAN type applications, that is not where the
bottleneck is...
and its not inconceivable to add an additional Python Execution Gigabit
Backbone to a cluster of machines, dedicated to this remote calling task...

Its almost too good for my simple little local job, but I am still reading...

I have to remember to thank Bruno for the pointer...

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Enhanced Listbox

2006-08-05 Thread H J van Rooyen

 drodrig [EMAIL PROTECTED] wrote:

(top posting fixed)


| H J van Rooyen wrote:
|  drodrig [EMAIL PROTECTED]
| 
| 
|  | My apologies if this question has been asked an answered.
|  |
|  | I am looking for a tkinter grid control or enhanced listbox that can
|  | act as a receipt for a cash register program. I would like the widget
|  | to contain a visible grid of columns and rows. I've tried binding
|  | multiple listboxes to a scrollbar. This works OK, but I am missing the
|  | vertical lines dividing each row and I can't seem to figure out how to
|  | set the height (or vertical margin) of each row in the listbox(es). If
|  | I could do these things my current implementation might be OK. Or, I
|  | could just use a pre-packaged solution, if I coud find one.
|  |
|  | Any help is appreciated.
|  |
|   - you could try making your columns different background colours if this is
|  acceptable...
| 
|  - Hendrik
|
| Thanks for your reply. I have done this. It certainly helps. My biggest
| concern right now is the vertical space between the fonts in each row.
| I need more than the default and I'm not sure on how to go about
| achieving this. Also, the vertical lines between each row would be
| nice.
|
I also don't know how to do this - as far as I know the height and width
parameters of the listbox widget refer to number of lines and characters
respectively - I cant see anything that gives you control over the height of a
line - but maybe I am looking in the wrong place - I know that if you use a
bigger font the individual lines get bigger - but it looks proportional to me.

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Running queries on large data structure

2006-08-04 Thread H J van Rooyen

Christoph Haas [EMAIL PROTECTED] wrote


| On Wednesday 02 August 2006 22:24, Christoph Haas wrote:
|  I have written an application in Perl some time ago (I was young and
|  needed the money) that parses multiple large text files containing
|  nested data structures and allows the user to run quick queries on the
|  data. [...]
|
| I suppose my former posting was too long and concrete. So allow me to try
| it in a different way. :)
|
| The situation is that I have input data that take ~1 minute to parse while
| the users need to run queries on that within seconds. I can think of two
| ways:
|
| (1) Database
| (very quick, but the input data is deeply nested and it would be
|  ugly to convert it into some relational shape for the database)
| (2) cPickle
| (Read the data every now and then, parse it, write the nested Python
|  data structure into a pickled file. The let the other application
|  that does the queries unpickle the variable and use it time and
|  again.)
|
| So the question is: would you rather force the data into a relational
| database and write object-relational wrappers around it? Or would you
| pickle it and load it later and work on the data? The latter application
| is currently a CGI. I'm open to whatever. :)
|
| Thanks for any enlightenment.
|
|  Christoph

Not sure if this is of any use - but I have noticed that dict lookups in Python
is blindingly fast - but it seems to me to use them would be as much trouble to
you as converting the data into a shape for the database in third normal form...

Unless of course your parser is already doing something like that...

There are also some fancy packages for tree structures around, but I don't know
anything useful about them.

- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to force a thread to stop

2006-08-04 Thread H J van Rooyen

Carl J. Van Arsdall [EMAIL PROTECTED] wrote:


| Alex Martelli wrote:
|  H J van Rooyen [EMAIL PROTECTED] wrote:
| 
| 
|  Paul Rubin http://[EMAIL PROTECTED] Writes:
| 
|  | H J van Rooyen [EMAIL PROTECTED] writes:
|  |  *grin* - Yes of course - if the WDT was enabled - its something that
|  |  I have not seen on PC's yet...
|  |
|  | They are available for PC's, as plug-in cards, at least for the ISA
|  | bus in the old days, and almost certainly for the PCI bus today.
| 
|  That is cool, I was not aware of this - added to a long running server it
will
|  help to make the system more stable - a hardware solution to hard to find
bugs
|  in Software - (or even stuff like soft errors in hardware - speak to the
|  Avionics boys about Neutrons) do you know who sells them and what they are
|  called? -
| 
| 
|  When you're talking about a bunch of (multiprocessing) machines on a
|  LAN, you can have a watchdog machine (or more than one, for
|  redundancy) periodically checking all others for signs of health -- and,
|  if needed, rebooting the sick machines via ssh (assuming the sickness is
|  in userland, of course -- to come back from a kernel panic _would_
|  require HW support)... so (in this setting) you _could_ do it in SW, and
|  save the $100+ per box that you'd have to spend at some shop such as
|  http://www.pcwatchdog.com/ or the like...
| 
| 
| 
| Yea, there are other free solutions you might want to check out, I've
| been looking at ganglia and nagios.  These require constant
| communication with a server, however they are customizable in that you
| can have the server take action on various events.
|
| Cheers!
|
| -c
 Thanks - will have a look - Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-04 Thread H J van Rooyen

 Bruno Desthuilliers [EMAIL PROTECTED]wrote:


| H J van Rooyen wrote:
|   Bruno Desthuilliers [EMAIL PROTECTED] wrote:
| (snip)
|  | If my original post was unclear I am sorry - the point I want answered,
if
|  | possible, is how to make the client code effectively updateable on the
fly -
|  | because the answer to this will influence the whole design of the rest of
the
|  | system...
|  |
|  |This is something I have been thinking about... IMHO what you want is
|  |not to update client code on the fly, but to make the client mostly a
|  |kind of interpreter for what the server sends in. That is, the client
|  |code itself doesn't contain any application logic, it gets it from the
|  |server and execute it. This can certainly be done with Pyro.
|  |
|  |Now while this may be an interesting project, I'm not really sure it's
|  |worth the effort when we already have HTTP, HTML and AJAX...
| 
|  You may be right and it might not be worth the trouble  - but what you
mention
|  above is closer to the sort of thing I have in mind - it is essentially
using
|  python to create a script language, and moving scripts around - but hey -
python
|  is already a script language...
|
| Yes, but it's not (alas) supported by browsers...
|
|  so if Pyro is for 'moving the scripts around' - Then that is what I must
look at
|  very hard...
|
| It's not for moving the scripts around, it's for remote objects - kind
| of like Java's RMI, but, well, much more pythonic !-). Now the point is
| that Python being very powerful when it comes to dynamism and
| introspection, it should be possible to have a common client that
| basically just knows how to connect to the application server (using
| pyro). Once connected, the client asks the server for a set of objects
| (forms, menus etc) and the corresponding data. These objects then use
| the same mechanism to interact with the server. It's basically similar
| to the interaction between a browser and a web app - in that the client
| is potentially able to run any application sent by the server -, but
| with much more  specialized client and app server and another protocol -
| and no other language than Python.
|

This is getting more and more interesting - its not the simple minded mechanism
I had in mind, but it will achieve the same thing, and it exists already - and I
can imagine it to be a very powerful mechanism, if I understand you correctly -
I am going to have to cry time out! to go and do some reading...

Thank you. - Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-04 Thread H J van Rooyen

Dennis Lee Bieber [EMAIL PROTECTED] wrote:


| On Thu, 3 Aug 2006 09:17:41 +0200, H J van Rooyen
| [EMAIL PROTECTED] declaimed the following in comp.lang.python:
|
|  Can I not use the ssl module for encrypting the connections? - Please also
|  understand that the system is aimed at small to medium companies, in
ouse  -
|  From my perspective the only valid reason to use a database would be for
the
|  ease of reporting - the files are not large - and the speed of a dict lookup
in
|  python is hard to beat for normal transaction processing...
| 
| You might want to read the Kode Vicious column in a recent issue
| of Queue (probably last months issue -- it's been in my carry-bag for a
| few weeks).
|
| For an in house effort, encrypting the LAN traffic is probably not
| the most meaningful focus. Securing the data /storage/ is more important
| -- why secure the LAN traffic if someone can walk off with a backup of
| unsecured database. And who'd want to even spend time with a LAN sniffer
| on unencrypted traffic if that same backup is available for filching.
| 

This makes sense - message is - lock your server room...

|  NO! the last thing on my mind - want a dynamic process similar to banking
|  terminals - see my response to Simon please
| 
| ? ATMs? Or internal clerk consoles?

Semantics - sorry - neither - thinking of credit card terminals - in which area
I have dabbled in a bit...

These things have horrendously complex terminal management systems and elaborate
mechanisms to download all manner of parameters to change their behaviour... -
most have their internal state controlled by the server, sometimes formally,
sometimes just via param download...


| Pretty much everything is already in the terminal software -- what
| the operator has access to, and sees, is dependent upon the privileges
| defined for their account. No dynamic loading of code (for security,
| I'd not even permit remote updates -- I'd require a floppy or CD from
| inside the secure box to change operating software; as soon as you
| permit updates to be pushed from outside you expose the risk of a
| cracker pushing a customized code set).
|

I was not aiming for this paranoid level of security - when I said secure  or
reliable I was just looking for something that would work and that I could
trust not to fall over all the time...

On the small boxes, the loading of software mechanism varies from manufacturer
to manufacturer - some allow, others disallow the download and activation of new
apps - likewise for the update of existing ones - but most banks don't use these
mechanisms, even if they are available - they all tend to bring the device in to
a trusted facility.  I don't know one of them that actually use the mechanism on
a per transaction basis, because it would be, amongst other things, too slow -
but most of the systems can force the terminal into a reload of at least its set
of parameters the next time it logs in - and this mechanism is used by for
instance AMEX to vary the messages displayed on their terminals - not quite
code update - but the user can't tell the difference.

I used the example because this sort of facility is the kind of thing I want to
find out if Python could do, in a more dynamic way than what the terminals that
can use it, actually use it - little thinking that I was sowing confusion -
sorry...

If you are familiar with the sort of Terminal Management Systems I am talking
about, that control the behaviour of the remote box via parameter download -
then what I want find out is how to do that in Python, but with the added
proviso that I must also be able to download pieces of the application - where
download in this sense is just to a PC in the next office on the local LAN -
So far the Pyro package that Bruno has steered me towards sounds the most
promising way of doing this - but I still haven't been able to research it ...

Thanks for the input and sorry about the confusion.

- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-04 Thread H J van Rooyen

Dennis Lee Bieber [EMAIL PROTECTED] wrote:


| On Thu, 3 Aug 2006 14:05:19 +0200, H J van Rooyen
| [EMAIL PROTECTED] declaimed the following in comp.lang.python:
|
|  What I mean by this is that the server does stuff that I think belongs on
the
|  client -
|  like getting involved in the nitty gritty of what the client should
display -
|  I want the client to be smart enough to do the assembly of the elements of a
|  transaction
|  by itself, going back to the server for data only when its needed - remember
|
| One thing to consider: Where is the separation between the database
| and the client. I believe most textbooks these days tend recommend:
|
| [db-server] - [app-server] - [client]
|
| (db-server and app-server can be the same hardware; the idea is that
| clients do not have direct access to the database system, and hence the
| back-end can be changed out without affecting any client... also,
| clients don't need to handle database errors, etc.)

Agreed - I would also need this application server to do the server end of my
terminal management system

|
|  so I see the client interacting with the server quite a lot, eventually to
be
|  able do things like auto completion of things like stock codes and
descriptions,
|  customer details, etc. - but I don't want every keystroke flying over the
LAN
|  and
|  being handled by the server...
| 
| And where did you see the client obtaining the completion data --
| direct access to some other database tables or did you intend to
| download /all/ possible data.

no just a framework of more or less static stuff like document types, name and
address data, and account names and codes that is not subject to continous
change... *grin* I would have to apply *some* skull sweat to the problem...

|
| Typical web-based applications may have a minimal bit of data
| validation running on the client (JavaScript ... things like making sure
| /something/ has been entered into required fields, but not verifying
| that it makes sense), and only when the user clicks on a submit is
| everything sent to the application server, which then generates the
| needed SQL from the data fields for submittal to the database server.
|
|  transaction is completed - like in a banking system, I envisage ways for the
|  client to 'poll' the server to get the state of the last transaction, to
make
|  this possible.
| 
| Bad choice... Upon submittal to the server, there should be a
| mandatory good/bad return code...


Here I take umbrage - not bad, good choice - let me elucidate - the return code
you are talking about is the normal thing, and it is the dead wrong way to
operate if that is all you do - what I am talking about is the failure
scenario - the way to make any transactionally based system robust is to have a
GetTranResult transaction that is routinely used before starting a new
transaction, to see if the previous one has completed properly - that way, the
client can either - continue with the new transaction, or - resubmit the old one
to try to get it to work or fail, or thirdly - advise the user that the previous
transaction has failed - it is, when you have thought about the flows and all
the possible ways in which they can fail - truly the only way to operate
reliably.

The above is the simple minded way to use such a facility -

You could also argue that the time to use this polling transaction is after
submitting the transaction, but if your return code is to be trusted, its not
needed - if the flows complete normally, its not needed - it is just needed for
built in recovery, and it works like a charm if both the server and the client
try to keep state over power failures and other disastrous events like losing
comms halfway through - especially for multi flow transactions that must update
different things on the server...

And it does no harm to ask the server the result of your last transaction when
you come up after power failure - you can then set the screens and stuff up to
the point where the server knows about them and have the user just curse a bit,
instead of a lot...

And most importantly, the data is safe (unless the database is corrupted, in
which case the likelyhood is high that yer screwed in any case) - and on this
note - if you have the reversed transaction too - i.e. a kind of
GetPreviousLoggedTransactionResult from the server to the client, you can make
recovery less painful, even in the case of database corruption...

Bad choice indeed!  *snorts*

;-)

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to force a thread to stop

2006-08-04 Thread H J van Rooyen

Gerhard Fiedler [EMAIL PROTECTED] wrote:

| On 2006-08-03 06:07:31, H J van Rooyen wrote:
|
|  Thanks - will check it out - seems a lot of money for 555 functionality
|  though
| 
|  Especially if like I, you have to pay for it with Rand - I have started
|  to call the local currency Runt...
|
| Depending on what you're up to, you can make such a thing yourself
| relatively easily. There are various possibilities, both for the
| reset/restart part and for the kick-the-watchdog part.
|
| Since you're talking about a 555 you know at least /some/ electronics :)

*grin* You could say that - original degree was Physics and Maths ...

| Two 555s (or similar):
| - One wired as a retriggerable monostable and hooked up to a control line
| of a serial port. It needs to be triggered regularly in order to not
| trigger the second timer.
| - The other wired as a monostable and hooked up to a relay that gets
| activated for a certain time when it gets triggered. That relay controls
| the computer power line (if you want to stay outside the case) or the reset
| switch (if you want to build it into your computer).
|
| I don't do such things with 555s... I'm more a digital guy. There are many
| options to do that, and all a lot cheaper than those boards, if you have
| more time than money :)

Like wise - some 25 years of amongst other things designing hardware and
programming 8051 and DSP type processors in assembler...

The 555 came to mind because it has been around for ever - and as someone once
said (Steve Circia ?) -
My favourite programming language is solder...  - a dumb state machine
implemented in hardware beats a processor every time when it comes to
reliability - its just a tad inflexible...

The next step above the 555 is a PIC... then you can steal power from the RS-232
line - and its a small step from PIC to PIG...

Although this is getting bit off topic on a language group...

;-)  Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-04 Thread H J van Rooyen

Nick Vatamaniuc [EMAIL PROTECTED] wrote:



| Hendrik,
|
| ---snip---
| Now part of the reason I would like to go the transaction type route
| instead of the  per user route is robustness and maintainability, and
| the ability it would give me to introduce new transaction types easily
| - as I see it if say an invoice's GUI code is stable I would never have
| to touch it again even if I combine it with anything else, as it would
| have been designed from the start to combine with others of it's own
| ilk, under a kind of communications controller that is standard...
| ---snip---
|
| It could be possible to separate your GUI into various modules. So you
| could have for example:
| BillingGUI.py
| InvoicingGUI.py
| QueryGUI.py
| and so on.
| Then your central control application (Application.py) would get the
| set of module names allowed for that client to run during login. So
| after the user logs in, the next thing would be to SELECT ...  all
| the GUI modules from the database to be downloaded. The client won't
| know which ones are there, only the server.
|
| So the set of possible GUIs will be sent over to the client (preferable
| in a zipped form). They are unzipped in some temporary folder (here you
| can do some caching to only download if the set changed).
|
| Then it would be imporant for you to create some nameing rule or some
| interface so the Application.py will know what GUI modules look like.
| For example you  could have the pattern [Capitalizedname]GUI.py be a
| GUI module. The Application.py will then inspect the folder, and create
| a button and label for each possible GUI module and present that to the
| user. When the user clicks on the Button, the Application.py window
| gets hidden and the [Modulename]GUI.py module is executed. When done,
| the Application.py will be shown again and the user can either continue
| with another module they are allowed to use or quit.
|
| How does that sound?

This is the sort of thing I am looking for, thanks - its a bit rough as it
depends on magic gui names, but hey - I think it would be easy to implement,
even not using magic names - the server could tell the core app the names of the
files explicitly during the logon type dialog... *grin* that will move the magic
out of the client and on to the server...


| Also, you mentioned that you won't have more than a couple of simple
| fill-in forms and with drop-down options and so on. HTML then might be
| the way to go. If that's all there will ever be just try to do HTML
| (see Cherrypy, Turbogears and others). If your GUI will be more
| complicated in the future, just stick with what you know (Tkinter for
| example).
|
| Good luck,
| Nick Vatamaniuc
|

Thank you for the support - now I would like to call Time out - I have a lot
of reading to do...

- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-04 Thread H J van Rooyen

 Dennis Lee Bieber [EMAIL PROTECTED] wrote:



| On Thu, 3 Aug 2006 16:50:15 +0200, H J van Rooyen
| [EMAIL PROTECTED] declaimed the following in comp.lang.python:
|
| 
|  This is broadly what I had in mind, yes - but sort of down to a transaction
|  level - this user does invoicing, this one enters cheques, this one does
credit
|  notes, and their supervisor can do all three, and in a different department
its
|  different because the jobs are different, but the invoicing GUI module is
the
|  same for wherever its used...
| 
| Confusing use of transaction... Many are probably looking at
| transaction in terms of DBMS -- eg: a sequence of SQL operations
| (inserts/updates/deletes) that ALL must be successful (and committed)
| or, if any operation fails, ALL operations will be undone (rolled back)
| as if none had been performed.
|
| What you describe is something I'd refer to as different operator
| tasks.

Sorry - I have spent too long in an environment where a transaction is something
you built, shipped, and got an answer for...

|
| For this control, and presuming you do NOT want to use a web
| interface, I'd still build all capability (ie, all menu and form
| definitions) into the client that is installed on all user stations.
| THEN I'd use the application server (since I still feel you want to
| control access to the database to one central point, not have to create
| a user account in the DBMS for each employee using the clients) to
| handle a login from the client -- the login would be used to access a
| privilege table from the DBMS. This privilege table is essential a long
| record of booleans -- one for each menu/form/task in the client. The
| privilege record is sent to the client; the client uses the record to
| enable and disable the relevant menu/form/task so that the user can only
| activate the functions valid for them.
|
 *grin* this is the easy - cop out route - there is of course nothing
intrinsically wrong with it - I was just trying to find out how to do the harder
bits in Python - namely to dynamically present different things...


| Otherwise you have a situation where, say a lowly data-entry clerk
| has been using the application, maybe makes a mistake that requires
| supervisor override, and the supervisor then has to wait for their
| modules to be downloaded and started to correct the mistake. (Note: one
| menu entry that should be on the all-in-one client is an ability to
| change login without having to shut down the client -- basically the
| client does a log-off of the application server, then a fresh log-in
| with new parameters and gets a new privilege record with which to
| reconfigure all the menu/form/task GUI).
|

This is a disadvantage that I had not thought about - I was not yet this far
down the track

| If you go the web application route, each login would use a cookie
| to control session, so the application server can determine what
| functions to present to the user. You might even be able to use
| something like Plone to build the application server; it already has
| capability to present different views based upon login.

Know squat about Plone - another thing to add to my list of reading *sigh*
|
|  My thinking is simpler than this, because you are already thinking in data
base
|  speak - now dont get me wrong - I realise that I will have to use a
database -
|  but for me to start thinking in terms of views and stuff is kind of
premature
|  when I dont even have a clear picture in my head of the kind of data the
said
|  management system should keep, as I am not sure of what can, and cannot be
done.
| 
| We're talking computer software -- enough money and time and you
| could have the sun, moon, and stars (granted, a decade ago I /was/
| involved with swapping out one satellite ephemeris package for another,
| so it was literally sun, moon, and stars G)
|

sounds like it was fun...

| You need to determine
|
| 1) architecture partitioning (DBMS - thick client; DBMS -
| application server - thick client, DBMS - application/web server -
| thin client) [Thick client: Python program that handles GUI and talks to
| application server or DBMS; Thin client: web browser forms with some
| Javascript/AJAX].

I am kind of egregious - despite all the sound advice I am getting - I am still
thinking (from the back end) of:

dbms  app server  thick client (python)

|
| 2) Database schema (done without care of the final DBMS); take into
| account things you may not think of as the main data of the application
| -- things like the above privilege control (in the case of the
| DBMS-thick client, it means using the grant tables and managing client
| accounts per user, in the application server model you only have one
| DBMS user that is the application server, but still have client user
| accounts to manage as application data). If the DBMS has stored
| procedures, you may need some of those... Heck, in the DBMS-thick
| client model, you could let any client access ANY form

Re: How to force a thread to stop

2006-08-04 Thread H J van Rooyen

Gerhard Fiedler [EMAIL PROTECTED] wrote:


| On 2006-08-04 02:33:07, H J van Rooyen wrote:
|
|  The next step above the 555 is a PIC... then you can steal power from the
|  RS-232 line - and its a small step from PIC to PIG...
|
| I see... you obviously know what to do, if you want to :)
|
| But I'm not sure such a device alone is of much help in a typical server. I
| think it's probably just as common that only one service hangs. To make it
| useful, the trigger process has to be carefully designed, so that it
| actually has a chance of failing when you need it to fail. This probably
| requires either code changes to the various services (so that they each
| trigger their own watchdog) or some supervisor program that only triggers
| the watchdog if it receives responses from all relevant services.
|
| Gerhard

 This is true - its trivial to just kill the whole machine like this, but its
kind of like using a sledgehammer to crack a nut - and as you so rightly point
out - if the process that tickles the watchdog to make it happy is not (very)
tightly coupled to the thing you want to monitor - then it may not work at all -
specially if interrupts are involved - in fact something like a state machine
that looks for alternate occurrences of (at least) two things is required - the
interrupt gives it a kick and sets a flag, the application sees the flag and
gives it the alternate kick and clears the flag, and so on, with the internal
tasks in the machine passing the ball in this (or some other) way - that way
you are (relatively) sure the thing is still running... but it needs careful
design or it will either kill the machine for no good reason, (when something
like disk accesses slow the external (user) processes down ) , or it will fail
to fire if it is something that is driven from a call back - the app may be
crazy, but the OS may still be doing call-backs and timing stuff faithfully -
you cant be too careful...

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-03 Thread H J van Rooyen

Nick Vatamaniuc [EMAIL PROTECTED] wrote:


| HJ,
|
| As someone already posted, the backend sounds very much like a
| database, so why not use a database: transactions, specific views for
| different users, limited access and so on = database!
| Give PostgresSQL a try...

*nods* - looks like I am going to have to do this

| As far as presenting a different GUI to users, you can also do it based
| on the database.  In other words have a common login screen and if the
| usertype from the database is returned as 'restricted' draw one
| interface, if it is returned as 'full' draw the full interface. Even if
| the restricted user will get the full interface up it won' t be
| functional because the database would restrict writes to certain
| tables/columns.

This is the guts of my question - if I dont know all the types now, how do I
make the front end so that I can easily update it as time reveals new
requirements - a la banking style terminals - see my reply to Simon please

| Remote update of code is also possible, but you'll have to implement
| some kind of update server to which you can periodically send Python
| files, those files will be installed on the machine by the update
| server. You can try playing with Twisted to handle the networking. Or
| just write a simple script to send  stuff over scp/ssh -- that's what I
| would do (start the ssh server, install public keys and then just scp
| stuff over to the machines assuming they are online most of the
| time...).

This kind of addresses getting the stuff on to the server on the site for me - I
would like the front end to be more dynamic...

|
| The problem will be if something goes wrong in the updated file or with
| the update server then the whole system will be down (an off-by-one
| error in the GUI db client code and all of the sudden all your users
| will be writing bad data to the database... all at the same time). So
| you will need to do frequent backups of the database, but you probably
| know this already...
|
| Hope this helps,
| Nick Vatamaniuc

*grin* yes and it scares the s**t out of me - this is why I like the do one
thing at a time to completion  approach - much easier to recover when things go
wrong...

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-03 Thread H J van Rooyen

Simon Forman [EMAIL PROTECTED] wrote:



| H J van Rooyen wrote:
|  Hi,
| 
|  I want to write a small system that is transaction based.
| 
|  I want to split the GUI front end data entry away from the file handling and
|  record keeping.
| 
|  Now it seems almost trivially easy using the sockets module to communicate
|  between machines on the same LAN, so that I want to do the record keeping on
one
|  machine.
| 
|  I want to keep the server machine as simple as possible - just doing
record
|  keeping on a stimulus response basis - I would prefer it to do one thing at
a
|  time to completion because this style of operation, though limited in
|  performance, keeps a lot of hassles out of life - a transaction has either
|  completed, or it has not - recovery scenarios are relatively easy...
| 
|  Up to this point, I don't have a problem - my toy system can create a dummy
|  transaction, and I can echo it from the server machine, with more than one
|  user machine running - so I think it is feasible to have several tens of
data
|  entry terminal systems running, served by one not very strong machine.
| 
|  Now what I would really like to do is to differentiate between the 'User
|  machines, so that some can do a full range of transactions, and others a
limited
|  range.
| 
|  And I would like to make this flexible, so that it becomes easy to introduce
new
|  transactions, without having to run around updating the code in all the user
|  machines, with the concomitant version number hassles.
| 
|  And I would like to do the whole thing in python - so my question is this -
is
|  it possible to do the equivalent of dynamic linking? - i.e. if I keep a list
of
|  what a user is allowed to do - can I somehow send him just the bits he needs
to
|  do the job, without having to change the static code on his machine? - it
seems
|  to me that the eval() thingy could possibly do this for me, by sending it
data
|  that makes it do import statements followed by calls to whatever... - will
this
|  work, or is there a better way?
| 
|  Or has all this been done already? - and no I don't want a web server and
php
|  and browsers and Java and html or xml... - I want to write something that
works
|  simply and reliably - its just short message accounting type data...
| 
|  - Hendrik
|
| Don't reinvent the wheel.  Use a database...

This believe it or not, is why I asked the question...

|
| You probably don't want to hear this, but what you just described is a
| GUI client front-end with a database backend.  The time it takes to
| download, install, and learn to use, say, postgres will be similar to
| the time you'd spend implementing what you've described above, but with
| at least 10 to 100 times the payoff.
|

In a way you are right - having just read postgres vs mySQL wars in another
thread on this group - but on the other hand I am lazy and dont really want to
spend time writing ISAM or hashed random access file methods either - I did my
share of that in the late sixties and early seventies - and I have not yet done
any research into the capabilities of the various contenders in this arena...
*ducks*

| As for updating the client on the fly, one strategy would be to keep
| the dynamic code in it's own module and have the clients reload()
| that module when you upload a new version of it to the client machines.
|
| Peace,
| ~Simon

This will work - but it is unsatisfying to me - I would have kind of liked to
have the client machine not even have all the code available - having the bits
that can change in one module implies some kind of build for every client if
they are to be to different - what I would rather write is the kind of thing
that is implemented in banking transaction terminals - the terminal has only the
code for the transactions that it is authorised to have, and these different
modules along with their parameters can be downloaded into it and activated on
the fly, one at a time...

And how to do that efficiently in python is really the question that I would
like to have answered, if possible...

Thanks for the response, Simon.

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: serial ports, threads and windows

2006-08-03 Thread H J van Rooyen

 Tom Brown [EMAIL PROTECTED]


| Hey people,
|
| I've written a python app that r/w eight serial ports to control eight devices
| using eight threads. This all works very nicely in Linux. I even put a GUI on
| it using PyQt4. Still works nicely.
|
| Then I put the app on on a virtual Windows machine running inside of vmware on
| the same Linux box.  Vmware only lets me have four serial ports so I run the
| app against four serial ports using four threads. The app did not respond
| quick enough to data from the serial ports and eventually hung.
|
| So, I tried one serial port and the app still did not respond quick enough to
| the single serial port. It eventually hangs.
|
| When the app hung, in each case, it was not hogging the cpu nor reading any
| data off the serial ports. The task manager didn't show it was doing anything
| at all.
|
| When it runs on Windows, could it be:
|
| 1) Just struggling to run inside of VMware?
|
| 2) Using threads with Qt on Windows is a problem?
|
| 3) Threads in python on Windows is a problem?
|
| Any ideas?
|
| Thanks,
| Tom

I cant help you really, but I can put what little weight I have behind you - I
am also struggling with serial port implementation - I posted here some time ago
and got some answers - and my intermittent failure is now down to about once a
week.

I found that while python's file handling and the GUI stuff works seamlessly
across platforms, the serial port handling seems quirky and platform dependant :

It is extraordinarly difficult to write non blocking reads that will work 'out
of the box' across platforms - in fact I dont know if it is possible..

And making a pipe non blocking is poison...

- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-03 Thread H J van Rooyen

Yu-Xi Lim [EMAIL PROTECTED] wrote:


| Simon Forman wrote:
|  Or has all this been done already? - and no I don't want a web server and
php
|  and browsers and Java and html or xml... - I want to write something that
works
|  simply and reliably - its just short message accounting type data...
| 
|  - Hendrik
| 
|  Don't reinvent the wheel.  Use a database...
| 
|  You probably don't want to hear this, but what you just described is a
|  GUI client front-end with a database backend.  The time it takes to
|  download, install, and learn to use, say, postgres will be similar to
|  the time you'd spend implementing what you've described above, but with
|  at least 10 to 100 times the payoff.
| 
| 
|  As for updating the client on the fly, one strategy would be to keep
|  the dynamic code in it's own module and have the clients reload()
|  that module when you upload a new version of it to the client machines.
|
| Yes, indeed, using a database with a GUI front end is the best way to
| get something that works simply and reliably. Writing everything in
| Python isn't always the best solution. Python, however, is very good at
| interfacing with most existing applications and thus makes a great glue.
|
| Using a proper DB system would give up transactions, multiple users, and
| access control, which you have said you required, and probably more
| features which you hadn't realized you needed but soon will when you
| scale up beyond a toy system (optimized queries, backups, load
| balancing, encrypted connections, etc).

Can I not use the ssl module for encrypting the connections? - Please also
understand that the system is aimed at small to medium companies, in house  -
From my perspective the only valid reason to use a database would be for the
ease of reporting - the files are not large - and the speed of a dict lookup in
python is hard to beat for normal transaction processing...

|
| As for updating the applications, why not just put them on the server
| for each user/client to retrieve? There are of course several ways of
| retrieving the centrally stored GUI program, and most likely you're
| thinking Windows file sharing (which would require restarting the client

NO! the last thing on my mind - want a dynamic process similar to banking
terminals - see my response to Simon please

| whenever updates are available). But don't rule out HTTP. Among the

I have been shying away from this - due to mental laziness - but obviously I
have to look at it - thanks

| benefits of web apps are the ability to update the application on the
| fly and deploy it quickly. And no, web apps don't necessarily mean PHP,
| Java or XML. You can easily use plain HTML and Python to create the GUI
| and interface it with the database. AJAX may be th buzzword now, but it
| isn't necessary for everything.

Thanks will *have* to look at html






-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-03 Thread H J van Rooyen

Bruno Desthuilliers [EMAIL PROTECTED] wrote:


|H J van Rooyen a écrit :
| Hi,
|
| I want to write a small system that is transaction based.
|
| I want to split the GUI front end data entry away from the file handling and
| record keeping.
|
| Now it seems almost trivially easy using the sockets module to communicate
| between machines on the same LAN, so that I want to do the record keeping on
one
| machine.
|
| I want to keep the server machine as simple as possible - just doing record
| keeping on a stimulus response basis - I would prefer it to do one thing at a
| time to completion because this style of operation, though limited in
| performance, keeps a lot of hassles out of life - a transaction has either
| completed, or it has not - recovery scenarios are relatively easy...
|
|IOW, you want a SQL DBMS. May I recommand PostgreSQL ?
|

Looks like the way to go - after the argy bargy here in another thread seems
mySQL has no supporters left...

| Up to this point, I don't have a problem - my toy system can create a dummy
| transaction, and I can echo it from the server machine, with more than one
| user machine running - so I think it is feasible to have several tens of
data
| entry terminal systems running, served by one not very strong machine.
|
| Now what I would really like to do is to differentiate between the 'User
| machines, so that some can do a full range of transactions, and others a
limited
| range.
|
|Any decent SQL DBMS is able to handle this. It's kind of builtin...

Yes - if you do the whole job on the server - the architecture I have mind is
more like a banking terminal scenario - please see my reply to Simon

|
| And I would like to make this flexible, so that it becomes easy to introduce
new
| transactions, without having to run around updating the code in all the user
| machines, with the concomitant version number hassles.
|
|Then you want a web front end.

This seems to me to assume that the server does all the work

|
| And I would like to do the whole thing in python
|
|You'll at least need bits of SQL (but SQLAlchemy may hide away most of
|it) and HTML (but there are some python packages that knows how to build
|HTML from declarative Python code).
|

that is good news - which packages?

| - so my question is this - is
| it possible to do the equivalent of dynamic linking? - i.e. if I keep a list
of
| what a user is allowed to do
|
|In SQL : GRANT/REVOKE

again - centric thinking - I really would like to change the bits on the client,
as I explained to Simon

|
| - can I somehow send him just the bits he needs to
| do the job, without having to change the static code on his machine?
|
|HTTP/HTML.
|

everybody says this - I am being dragged, kicking and screaming...

| - it seems
| to me that the eval() thingy could possibly do this for me,
|
|Err... I thought you wanted a reasonnably secure system, but I may have
|misunderstood.
|

this is the guts of what I want - if eval is NFG then how do I implement such a
kind of dynamic linking of modules on the client?

| by sending it data
| that makes it do import statements followed by calls to whatever... - will
this
| work, or is there a better way?
|
| Or has all this been done already?
|
|Yes, it's called a web frontend for a SQL DBMS. There's no shortage of
|Python frameworks to do this kind of things.
|

I kind of wanted to avoid the web based stuff - the application data is so small
and trivial, in a sense.

| - and no I don't want a web server
|
|If you don't want Apache, there are Python-based application servers.
|CherryPy comes to mind.
|
| and php
|
|Why PHP ?
|

seems popular

| and browsers and Java
|
|Why Java ?
|

it addresses what I want - to dynamically and securely download bits of code and
execute them on the remote machine...

| and html or xml... - I want to write something that works
| simply and reliably
|
|We do write SQL-based web apps all day long, and I can tell you they are
|certainly more simple and reliable than whatever eval()-based home-made
|solution we could imagine !-)

Aah! but I would like you to stretch that imagination - to tell me how to do
some of what Java was designed to do, but better and easier, because this is
python we are talking about...

I saw something in another thread here - they were talking about weave - can I
use that if eval is nfg?

If my original post was unclear I am sorry - the point I want answered, if
possible, is how to make the client code effectively updateable on the fly -
because the answer to this will influence the whole design of the rest of the
system...

- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Programming newbie coming from Ruby: a few Python questions

2006-08-03 Thread H J van Rooyen

 
Dennis Lee Bieber [EMAIL PROTECTED] wrote:


| On Wed, 02 Aug 2006 22:25:35 +0200, Jarek Zgoda [EMAIL PROTECTED]
| declaimed the following in comp.lang.python:
| 
|  
|  At the end of day we will be these who count bodies. ;)
| 
| o/~ Listen children, to a story
| that was written long ago
| 'bout a kingdom, on a mountain
| and the valley far below ... o/~
| -- 

Oh the mountain sheep were sweeter, 
but the valley sheep were fatter,
we therefore deemed it meeter,
to carry off the latter..



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to force a thread to stop

2006-08-03 Thread H J van Rooyen

Alex Martelli [EMAIL PROTECTED] Wrote:


| H J van Rooyen [EMAIL PROTECTED] wrote:
|
|  Paul Rubin http://[EMAIL PROTECTED] Writes:
| 
|  | H J van Rooyen [EMAIL PROTECTED] writes:
|  |  *grin* - Yes of course - if the WDT was enabled - its something that
|  |  I have not seen on PC's yet...
|  |
|  | They are available for PC's, as plug-in cards, at least for the ISA
|  | bus in the old days, and almost certainly for the PCI bus today.
| 
|  That is cool, I was not aware of this - added to a long running server it
will
|  help to make the system more stable - a hardware solution to hard to find
bugs
|  in Software - (or even stuff like soft errors in hardware - speak to the
|  Avionics boys about Neutrons) do you know who sells them and what they are
|  called? -
|
| When you're talking about a bunch of (multiprocessing) machines on a
| LAN, you can have a watchdog machine (or more than one, for
| redundancy) periodically checking all others for signs of health -- and,
| if needed, rebooting the sick machines via ssh (assuming the sickness is
| in userland, of course -- to come back from a kernel panic _would_
| require HW support)... so (in this setting) you _could_ do it in SW, and
| save the $100+ per box that you'd have to spend at some shop such as
| http://www.pcwatchdog.com/ or the like...
|
|
| Alex

Thanks - will check it out - seems a lot of money for 555 functionality
though

Especially if like I, you have to pay for it with Rand - I have started to call
the local currency Runt...

(Typical South African Knee Jerk Reaction - everything is too expensive here...
:- )  )

- Hendrik



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-03 Thread H J van Rooyen

Yu-Xi Lim [EMAIL PROTECTED] wrote:


| H J van Rooyen wrote:
|  |
|  | And I would like to make this flexible, so that it becomes easy to
introduce
|  new
|  | transactions, without having to run around updating the code in all the
user
|  | machines, with the concomitant version number hassles.
|  |
|  |Then you want a web front end.
| 
|  This seems to me to assume that the server does all the work
|
| Depends on what you mean by all the work.

What I mean by this is that the server does stuff that I think belongs on the
client -
like getting involved in the nitty gritty of what the client should display -
I want the client to be smart enough to do the assembly of the elements of a
transaction
by itself, going back to the server for data only when its needed - remember
this is essentially an
accounting type data entry package - most of the stuff is typed in as text, when
processing documents from the outside, while the locally produced docs like
invoices would be generated by the system, to a large extent by making choices
amongst alternatives known to the server -

so I see the client interacting with the server quite a lot, eventually to be
able do things like auto completion of things like stock codes and descriptions,
customer details, etc. - but I don't want every keystroke flying over the LAN
and
being handled by the server...

In a sense I want to build an architecture that assembles a record from a mix of
user input and user choices out of alternatives (which unfortunately would have
to be kept on the server) and that then ships this to the server to process, and
to keep track of - such a record would be either accepted or rejected by the
server, and it would be the responsibility of the client to ensure that the
transaction is completed - like in a banking system, I envisage ways for the
client to 'poll' the server to get the state of the last transaction, to make
this possible.

|
| Operations such as filtering  results are best done at the server unless
| your have extremely high-bandwidth connections so that each client can
| examine the entire data set and perform the operations themselves (with
| minimal time of course, since your other clients may be waiting on that
| transaction).
|
| Transactions, too, will have to be supported by the server, or else you
| may be left with partial transactions if a client gets disconnected
| somehow as well as the need to implement complex locking systems yourself.
|
| As for the other conditions, such as privilege and access control, I
| think you'd find that centrally managed is the most manageable in the
| long run.
|
| You won't regret making it server-centric. The experts have already done
| the optimisations and have ways of getting around the possible
| bottleneck of having a single server perform most of the operations.
|
|  |Yes, it's called a web frontend for a SQL DBMS. There's no shortage of
|  |Python frameworks to do this kind of things.
|  |
| 
|  I kind of wanted to avoid the web based stuff - the application data is so
small
|  and trivial, in a sense.
|
| You'd find that the python frameworks, especially those modeled after
| Ruby on Rails, make creating trivial applications, such as the front-end
| you describe, trivial. Go take a look at Django and TurboGears and the
| others. Some have videos demonstrating stuff like how to make a
| blog/wiki/other-database-app in 5 minutes. Most come with a built-in
| webserver, though generally those aren't tested or guaranteed for
| high-load environments.

I get the feeling I am drinking out of a fire hose... I will look.

|
| All you need to add is a DB. Most recommend postgresql, and I'd
| recommend that too, to provide the features you are looking for. Avoid
| the lightweight DB systems such as Gadfly, sqlite, MS Jet/Access since
| those don't have the necessary features.


postgres seems the way to go - if there is anything that is coming across clear,
it is this.

Have you any ideas about the code change on the fly requirement? or is it a
complete no no?

thanks - Hendrik




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-03 Thread H J van Rooyen

 Bruno Desthuilliers [EMAIL PROTECTED] wrote:


|H J van Rooyen wrote:
| Bruno Desthuilliers [EMAIL PROTECTED] wrote:
|
|
8---
| |You'll at least need bits of SQL (but SQLAlchemy may hide away most of
| |it) and HTML (but there are some python packages that knows how to build
| |HTML from declarative Python code).
| |
|
| that is good news - which packages?

http://divmod.org/trac/wiki/DivmodNevow
http://divmod.org/trac/wiki/DivmodNevow/Athena
http://starship.python.net/crew/friedrich/HTMLgen/html/main.html
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/366000
http://dustman.net/andy/python/HyperText/
http://pyhtmloo.sourceforge.net/

Thanks for the references I will try to check them all out

8--
| If my original post was unclear I am sorry - the point I want answered, if
| possible, is how to make the client code effectively updateable on the fly -
| because the answer to this will influence the whole design of the rest of the
| system...
|
|This is something I have been thinking about... IMHO what you want is
|not to update client code on the fly, but to make the client mostly a
|kind of interpreter for what the server sends in. That is, the client
|code itself doesn't contain any application logic, it gets it from the
|server and execute it. This can certainly be done with Pyro.
|
|Now while this may be an interesting project, I'm not really sure it's
|worth the effort when we already have HTTP, HTML and AJAX...

You may be right and it might not be worth the trouble  - but what you mention
above is closer to the sort of thing I have in mind - it is essentially using
python to create a script language, and moving scripts around - but hey - python
is already a script language...

so if Pyro is for 'moving the scripts around' - Then that is what I must look at
very hard...

- thanks - Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is there an obvious way to do this in python?

2006-08-03 Thread H J van Rooyen

Nick Vatamaniuc [EMAIL PROTECTED] wrote:


|HJ,
|
|As far as GUI language/library goes:
|
|Some people suggested HTML,  but I think HTML is a very awkward way to
|create a good looking dynamic GUI that is _both_ easy to use and fast
|and easy to design (which is what you would want probably). Just to
|have a nice user editable table for example, you would have to jump
|through hoops (using Javascript, DOM, CSS etc), while you could do it
|much easier with PyGTK and wxPython, especially if you use a gui
|designer like Glade or wxGlade. Even Tkinter beats HTML as far as
|building GUIs in Python goes. I believe this might change in the future
|with the adaption of SVG but that will take a while... That said, if
|your interface can get by with just buttons, text boxes, and text
|areas HTML will be  the best choice.
|

At the moment my toy system just uses Tkinter-  Buttons, Labels, Entry boxes and
Listboxes (which I populate from a dict) - and it has logic in it to do only one
dummy transaction, which I just ship to the server machine where nothing
happens - it is just echoed back to the client which prints it on stdout - If I
stay with this it will be a most uninteresting GUI - but that is not the point
at issue now...

|
|As far as updating-on-the-fly goes:
|
|For the client to get the code on the fly you will have to implement
|some sort of a downloader in the first place that when the user logs
|in, it downloads the GUI code from the server and runs it. So if you
|update the code the day before the next day they will get a different
|interface, or if a new user/machine type is created you just have the
|new code ready on the server and it will automatically be downloaded
|and run, is that right?
|

This is broadly what I had in mind, yes - but sort of down to a transaction
level - this user does invoicing, this one enters cheques, this one does credit
notes, and their supervisor can do all three, and in a different department its
different because the jobs are different, but the invoicing GUI module is the
same for wherever its used...

|Here is then how I see your use case:
|1) You would define your business rules in your database, you will have
|usernames, user types, access rights, data tables, columns types,
|relations, views, etc...

Yes no matter how you do it, you need to keep a per user or per machine set of
what can be done. - in banking terms - a sort of Terminal Management System...

My thinking is simpler than this, because you are already thinking in data base
speak - now dont get me wrong - I realise that I will have to use a database -
but for me to start thinking in terms of views and stuff is kind of premature
when I dont even have a clear picture in my head of the kind of data the said
management system should keep, as I am not sure of what can, and cannot be done.

|2) Then each user type will have a specific interface GUI code kept on
|the server (perhaps as a zipped binary GUI.zip in a database column
|called ClientSpecificGUI).

I would like to split this down further - see above - so for each user there is
a sort of *pointer* to each of the kinds of transactions she can do, and these
are shipped separately and *linked* at the client side...

|3) The client starts your Application.py which is the same across all
|clients. They will enter their username/password. The Application.py
|then sends those to the server to log into the DB.

*nods*

|4) After successful login, the  Application.py performs a SELECT query
|to download the zipped GUI.py file.
|5) GUI.py is unzipped and executed to start the GUI. The Application.py
|code will pass the DB connection object to the GUI.py, so the GUI can
|continue to talk with the database. GUI.py runs and does its magic, in
|the meantime Application.py waits for GUI.py to finished and then both
|exit.

|Is that what you had in mind?

Very close - I have not even thought this far - I did not think of building a
GUI for each user, I thought of building it for each transaction - kind of a
series of things like my toy - and then I got stuck on the linking the separate
transaction guis into an app on the fly bit, which is why I started the
thread - I really want to know if it is possible to do this sort of thing in
Python, and so far Bruno has come up with Pyro, while everybody else (including
Bruno) is beating me over the head with HTML

Now part of the reason I would like to go the transaction type route instead of
the  per user route is robustness and maintainability, and the ability it
would give me to introduce new transaction types easily - as I see it if say an
invoice's GUI code is stable I would never have to touch it again even if I
combine it with anything else, as it would have been designed from the start to
combine with others of it's own ilk, under a kind of communications controller
that is standard...


|NOTE: This means that the client will need to have all the required
|libraries at just the right versions. Imagine that your user 

Re: Strange Tkinter Grid behaviour Problem

2006-08-02 Thread H J van Rooyen

Peter Otten [EMAIL PROTECTED] wrote:
|H  J van Rooyen wrote:
|
|  Hi,
| 
|  Still struggling with my GUI exercise -
| 
|  I have the following lines of code in a routine that is bound at
|  Key-Return to an instance of Entry :
| 
|  self.disp.Amount_des = Label(self.disp, text = self.dis_string, fg
|  =
|  'black', bg = 'yellow')
|  self.disp.Amount_des.grid(row = self.rownum, column=0, sticky =
|  'nesw')
| 
|  self.disp.Amount = Label(self.disp, text = self.retstring, fg =
|  'black',
|  bg = 'green')
|  self.disp.Amount.grid(row = self.rownum, column=1, sticky =
|  N+S+E+W)
| 
|  The second call to the grid method fails as follows:
| 
|  Exception in Tkinter callback
|  Traceback (most recent call last):
|File E:\PYTHON24\lib\lib-tk\Tkinter.py, line 1345, in __call__
|  return self.func(*args)
|File C:\WINDOWS\DESKTOP\Entry1.py, line 243, in entryend
|  self.disp.Amount.grid(row = self.rownum, column=1, sticky = N+S+E+W)
|  TypeError: cannot concatenate 'str' and 'instance' objects
| 
|  If I change the N+S+E+W to the 'nsew' form, it works no problem...
| 
|  Weird - at other places in the program the form:  sticky = N+S+E+W works
|  without a problem.
|  I found the 'nsew' form by trial and error...
| 
|  self.disp is a window different from the current one - it is used to
|  display a record entry as it is built up field by field. - the code
|  fragment above is what inserts the description of the entry and the
|  entered data in a row in the window used for displaying, when the user
|  hits the enter key.
| 
|  Is this a bug, or am I still doing something wrong?
|
| You have probably defined your own, say, E somewhere in your module:
|
| E = ... # whatever
|
| This can easily be fixed by using another name. But what you are really
| doing wrong is using the
|
| from Tkinter import *
|
| star-import which drastically increases the likelihood of such name clashes.
| I recommend using qualified names, abbreviated if you like:
|
| import Tkinter as tk
|
| ... tk.N + tk.S + tk.E + tk.W ... # a bit longer, but worth the effort
|
| Of course this could still go wrong if you do
|
| tk = 42
|
| somewhere in your module...
|
| Peter

Well spotted that man! the offending line was:

def entryend(self,S):
This gets done on carriage return

The 'S is not actually used by me - it was added because the callback passes
Something back and I got an error earlier while I was still using pack...
*grin*

This also explains why it only happens here and not elsewhere...

Problem sorted - False alarm!

- Thanks

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: BCD List to HEX List

2006-08-02 Thread H J van Rooyen

John Machin [EMAIL PROTECTED] wrote:

| [EMAIL PROTECTED] wrote:
|
| My version assumes three subroutines: extracting
|  nibbles, shifting, and adding, Those are pretty simple, so I asked
|  if he needed them rather than presenting them.
|  Assuming we have
|  them, the algorithm is three lines long.
|
| Perhaps you could enlighten us by publishing (a) the spec for each of
| the get_nibble(s), shift, and add subroutines (b) the three-line
| algorithm (c) what the algorithm is intended to achieve ...
|
| 
|  He took a while to state the problem, but was clear from the start
|  that he had lists of digits rather than an integer datatype.
|
| Yes, input was a list [prototyping a byte array] of decimal digits. The
| OUTPUT was also a list of something. A few messages later, it became
| clear that the output desired was a list of hexadecimal digits. Until
| he revealed that the input was up to 24 decimal digits,  I was pursuing
| the notion that a solution involving converting decimal to binary (in a
| 32-bit long) then to hexadecimal was the way to go.
|
| What is apparently needed is an algorithm for converting a large
| number from a representation of one base-10 digit per storage unit to
| one of a base-16  digit per storage unit,  when the size of the number
| exceeds the size (8, 16, 32, etc bits) of the registers available. Is
| that what you have?
|
| Cheers,
| John

I actually read most of this thread as it happened and could not really figure
out what the OP was on about.

If the above is a true statement of the problem, then its more difficult to do
in a high level language, when the results exceed the native size that the
compiler or interpreter writers thought was a reasonable number of bits.

- ten to the 24 is of the order of 80 binary bits ...

So you need a (say) twelve byte result field for the binary... (thats three 32
bit values concatenated)
you clear the result field out to zero.
Then you feed in the decimal digits, from the most significant side, into a
routine that multiplies the result by ten and then adds the digit. (yes you have
to write this twelve byte Ascii/binary thing yourself)
When you have done this for all the digits, you have a binary number, and
getting hex from binary a nibble at a time is easy...

Well its easy in assembler, even on a cripple little 8 bit processor, anyway...
In python I would take a hard look at what I could do with the decimal module -
doing the reverse of the above but dividing by 16 repetitively and using the
remainder or the fraction to give the hex numbers in lsb to msb order, and doing
a lookup (prolly using a dict) to get the hex digits...

just my $0.02...

- Hendrik



-- 
http://mail.python.org/mailman/listinfo/python-list


Is there an obvious way to do this in python?

2006-08-02 Thread H J van Rooyen
Hi,

I want to write a small system that is transaction based.

I want to split the GUI front end data entry away from the file handling and
record keeping.

Now it seems almost trivially easy using the sockets module to communicate
between machines on the same LAN, so that I want to do the record keeping on one
machine.

I want to keep the server machine as simple as possible - just doing record
keeping on a stimulus response basis - I would prefer it to do one thing at a
time to completion because this style of operation, though limited in
performance, keeps a lot of hassles out of life - a transaction has either
completed, or it has not - recovery scenarios are relatively easy...

Up to this point, I don't have a problem - my toy system can create a dummy
transaction, and I can echo it from the server machine, with more than one
user machine running - so I think it is feasible to have several tens of data
entry terminal systems running, served by one not very strong machine.

Now what I would really like to do is to differentiate between the 'User
machines, so that some can do a full range of transactions, and others a limited
range.

And I would like to make this flexible, so that it becomes easy to introduce new
transactions, without having to run around updating the code in all the user
machines, with the concomitant version number hassles.

And I would like to do the whole thing in python - so my question is this - is
it possible to do the equivalent of dynamic linking? - i.e. if I keep a list of
what a user is allowed to do - can I somehow send him just the bits he needs to
do the job, without having to change the static code on his machine? - it seems
to me that the eval() thingy could possibly do this for me, by sending it data
that makes it do import statements followed by calls to whatever... - will this
work, or is there a better way?

Or has all this been done already? - and no I don't want a web server and php
and browsers and Java and html or xml... - I want to write something that works
simply and reliably - its just short message accounting type data...

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Strange Tkinter Grid behaviour Problem

2006-08-01 Thread H J van Rooyen
Hi,

Still struggling with my GUI exercise -

I have the following lines of code in a routine that is bound at Key-Return to
an instance of Entry :

self.disp.Amount_des = Label(self.disp, text = self.dis_string, fg =
'black', bg = 'yellow')
self.disp.Amount_des.grid(row = self.rownum, column=0, sticky = 'nesw')

self.disp.Amount = Label(self.disp, text = self.retstring, fg = 'black',
bg = 'green')
self.disp.Amount.grid(row = self.rownum, column=1, sticky = N+S+E+W)

The second call to the grid method fails as follows:

Exception in Tkinter callback
Traceback (most recent call last):
  File E:\PYTHON24\lib\lib-tk\Tkinter.py, line 1345, in __call__
return self.func(*args)
  File C:\WINDOWS\DESKTOP\Entry1.py, line 243, in entryend
self.disp.Amount.grid(row = self.rownum, column=1, sticky = N+S+E+W)
TypeError: cannot concatenate 'str' and 'instance' objects

If I change the N+S+E+W to the 'nsew' form, it works no problem...

Weird - at other places in the program the form:  sticky = N+S+E+W works without
a problem.
I found the 'nsew' form by trial and error...

self.disp is a window different from the current one - it is used to display a
record entry as it is built up field by field. - the code fragment above is what
inserts the description of the entry and the entered data in a row in the window
used for displaying, when the user hits the enter key.

Is this a bug, or am I still doing something wrong?

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Nested function scope problem (- variable definition branch)

2006-07-31 Thread H J van Rooyen
Gerhard Fiedler [EMAIL PROTECTED] wrote:

8-

| I'm not sure where you're trying to go. I think that most people (and even
| Bruno, who argued this issue most strongly) call Python variables
| variables every now and then, or maybe even usually. But it was helpful
| for me to see the difference between Python variables and, say, C
| variables. I think this has been a useful discussion in this respect. There
| is a difference, and it is important (IMO).
|
| Whether Python variables are in fact variables probably depends mostly on
| your definition of variable, and that's IMO a tough one -- a definition
| of variable that includes all those language elements that various
| languages call variables, and nothing else (that's the tough part).
| Whether that definition exists, and whether it includes Python variables,
| remains to be seen :)

I am not one for formal definitions but I think something like this:

if s is a python string containing hello world 
and I can write :

s = s + some extra stuff

then for me s is a variable - the fact that in the python implementation there
are two things, namely the original hello world string and the new longer one is
kind of irrelevant - if I try to print s I will get the new longer string, so
from where I stand s is a variable - it has changed over time from having one
value to another one...
and that is about the simplest definition you can get - its a symbolic reference
to something that can change over time - and in python it seems to me that every
name is a variable, cos you can tie the name to very different things at
different times:

 s = hello world
 print s
hello world
 s = s +  some more stuff
 print s
hello world some more stuff
 s = [1,2,3,4,5,6,7,8,9,0]
 print s
[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
 def foo():
 print banana

  s = foo
 s
function foo at 0x011DDE30
 s()
banana


s is surely a variable - there is nothing constant over time about it, and from
this point of view its very mutable indeed - and what is more - in every case,
after the assignment, unless you have stored a reference with a different name
to them, the old values look from a programmer's point of view as if they have
been overwritten - you can't use anything about s to get at them again...

Now there's a thought - an optional slice notation that slices s over time,
so that s{0} is the current s, and s{-1} the previous one, and so on, with
the default being s[{0}] the {0} being optional

This should be relatively easy to implement at the point of re binding the name
by replacing the pointer (or whatever) to the object with a stack of them.  I
think you could only do it in python, but I may be wrong...

Another world first for python?  - (TIC)

Look mommy! - I only use one variable name! 

- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to force a thread to stop

2006-07-30 Thread H J van Rooyen
Damjan [EMAIL PROTECTED] wrote:


|  | A common recovery mechanism in embedded systems is a watchdog timer,
|  | which is a hardware device that must be poked by the software every
|  | so often (e.g. by writing to some register).  If too long an interval
|  | goes by without a poke, the WDT hard-resets the cpu.  Normally the
|  | software would poke the WDT from its normal periodic timing routine.
|  | A loop like you describe would stop the timing routine from running,
|  | eventually resulting in a reset.
| 
|  *grin* - Yes of course - if the WDT was enabled - its something that I
|  have not seen on PC's yet...
|
| The intel 810 chipset (and all after that) has a builtin watchdog timer -
| unfortunetally on some motherboards it's disabled (I guess in the BIOS).
|
| How do I know that?
| Once I got Linux installed on a new machine and although the install
| went without a problem, after the first boot the machine would reboot on
| exactly 2 minutes.
| After a bit of poking around I found that hotplug detected the WDT support
| and loaded the driver for it (i8xx_tco), and it seems the WDT chip was set
| to start ticking right away after the driver poked it.

Yikes! some poking around - with two minutes to do it in - must have scarred
you for life!

- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: HERE I BUILT A QUICK MATRIX TOOOK 5 MINS

2006-07-29 Thread H J van Rooyen
Grant Edwards [EMAIL PROTECTED] wrote:

| On 2006-07-28, Paul McGuire [EMAIL PROTECTED] wrote:
|  ...USING A INFINITE MAGENTIC
|  FIELD!!!
| 
|  I have a vision of a sweeping magenta fabric rippling through the cosmos.
| 
|  Perhaps a mauvic, cyanic, or even aubergenic field would be more stylish.
|
| depends on what shoes you choose to go with it.
|
| --
| Grant Edwards   grante Yow!  My uncle Murray
|   at   conquered Egypt in 53
|visi.comB.C. And I can prove
|it too!!

I find myself in the unenviable position that I can no longer remember the
colour of magic as expressed in Terry Pratchett's books - was it something like
Octarine?

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to force a thread to stop

2006-07-29 Thread H J van Rooyen
Paul Rubin http://[EMAIL PROTECTED] Writes:



| H J van Rooyen [EMAIL PROTECTED] writes:
|  *grin* - Yes of course - if the WDT was enabled - its something that
|  I have not seen on PC's yet...
|
| They are available for PC's, as plug-in cards, at least for the ISA
| bus in the old days, and almost certainly for the PCI bus today.

That is cool, I was not aware of this - added to a long running server it will
help to make the system more stable - a hardware solution to hard to find bugs
in Software - (or even stuff like soft errors in hardware - speak to the
Avionics boys about Neutrons) do you know who sells them and what they are
called? -

Sorry if this is getting off topic on this thread... ( in a way it is on topic -
because a reset will stop a thread every time...)

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to force a thread to stop

2006-07-29 Thread H J van Rooyen

Dennis Lee Bieber [EMAIL PROTECTED] wrote:

| On Fri, 28 Jul 2006 08:27:18 +0200, H J van Rooyen
| [EMAIL PROTECTED] declaimed the following in comp.lang.python:
|
| 
|  Dennis - did your OS not have a ticker running?
| 
| That ancient machine, while round-robin, multi-priority,
| pre-emptive, seemed still to only deliver signals on deliberate
| blocking calls -- perhaps to prevent potential corruption if the signal
| had been delivered(handled) in the middle of some multi-instruction
| sequence. The OS level would see the ctrl-c, and set the signal bit
| in the task header -- but without the blocking I/O (typically), the code
| to activate a registered signal handler would not be invoked. Operation
| was something like: submit I/O request, AND(signal bits, signal mask) --
| invoke handler if non-zero, block for I/O return [or return directly for
| asynchronous I/O request]

- Hah! - so it *could* have responded - it just chose not to - so it was pre
emptive - but hey - what is different between modern OS's and what you are
describing? - it seems to me that there is just a lot of extra memory control,
as well as control over who is allowed to do what - in an effort to make things
more stable - and all this stuff just eats cycles and slows you down... (or
alternatively, makes the hardware more complex and expensive...)

But to get back to the OP's problem - basically the thread has to see some sort
of variable change, or receive a message (by examining something to see if there
is a message there) and then kill itself, or the OS must be told to stop giving
control back to the thread in question - which option will leave all the loose
ends in the thread loose...

So its either: hey mr nice thread please stop - or hey Mr OS - kill that
thread ... - now from the OS viewpoint - if the application implements some
threading itself - it may not even know that the thread exists - OS threads are
known variously as Tasks or Processes or Running Programmes - so using the
big guns on a thread may not be possible without killing the parent too...

So if you want to use the OS to kill the thread - it has to be a formal OS
thread - something started with a call to the OS, and not something that an
application implements by itself - and I am not familiar enough with Python
threading and dummy threading to pretend to know what is under the hood - but
I haven't seen an additional process appearing on my Linux box when I start a
thread - so its either something that Python does on its own without
registering the new thread with Linux - or I haven't looked closely enough...

So if somebody else can take over here, we might convince the OP that hey mr
nice thread is the way to go, even in the case that the thread in question is
an OS Process - after all - there has to be inter - task communication in any
case - so the cleanest solution is to build the kill in right from scratch...

Why do I think of COBOL:

read master_file_record at end go to end_routine

HTH   - Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: sending bytes to parallel port

2006-07-29 Thread H J van Rooyen
Timothy Smith [EMAIL PROTECTED] wrote:


| Grant Edwards wrote:
|  On 2006-07-28, Timothy Smith [EMAIL PROTECTED] wrote:
| 
| 
|  i've been trying to send an 8 byte string to my parallel port
|  under freebsd. the purpose is it to control a relay board. the
|  board simply responds to the output byte coming from the port.
|  eg.  0001 will set pin 1 high and flick the relay open.
|  todate i've attempted this with merely open() on /dev/ppi0 and
|  numpy for the byte array, but i just can't seem to get it
|  working. i know the parallel port works and i know the relay
|  board works (tested it with it's own windows ultility) so it's
|  just my crappy programming keeping me from success.
| 
| 
|  I'm guessing there's an implied request for help there
|  somewhere.  This would be a good start:
| 
|http://www.google.com/search?q=python+parallel+port
| 
|  I'd particularly recommend taking a look at the pyparallel
|  module found here:
| 
|http://pyserial.sourceforge.net/
| 
|  I've not used pyparallel, but based on my experience with
|  pyserial and some of Chris Liechti's other work, I'd bet
|  dollars to doughnuts it's your best option.
| 
| 
| yes, i did try pyparallel however it will not install on freebsd,
| setup.py errors.
|
| and yes i've done quite a bit of googling, i never expected it to be
| this difficult. i've done work with serial ports before. never parallel but.

What is on the other side of the link? - if its a small 8 bit micro - you may
simply be going too fast...

- Hendrik

|

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to force a thread to stop

2006-07-28 Thread H J van Rooyen

Dennis Lee Bieber [EMAIL PROTECTED] Wrote:

| On Thu, 27 Jul 2006 08:48:37 -0400, Jean-Paul Calderone
| [EMAIL PROTECTED] declaimed the following in comp.lang.python:
|
| 
|  If a thread never performs any I/O operations, signal handlers will still
|  get invokes on the arrival of a signal.
| 
| I thought I'd qualified that scenario -- from the point of view of
| one OS I've programmed, where signals were only handled as part of the
| I/O system (or, in more general, as part of any /blocking/ system call
| from an application -- not even a ctrl-c would have an effect unless
| the application invoked a blocking call, or explicitly polled the signal
| bits of its task header)
| --

I have to support this - a processor is only doing one instruction at a time, if
its not a multi core device - and the only ways that the operating system part
of the system can get control back from the *user program part* of the system
are:

a) when the User makes an OS call (like blocking I/O, or any OS request)
b) when the user code is interrupted by some hardware thingy and the OS part
handles the interrupt.

So on a processor that does not have protected instructions - if an idiot writes
something to the following effect :

*instructions to disable interrupts*

followed by :

*instructions that go into an infinite loop AND that make no OS calls*

the whole bang shoot stops dead - Reset your machine...

Dennis - did your OS not have a ticker running?

- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Threads vs Processes

2006-07-28 Thread H J van Rooyen
Dennis Lee Bieber [EMAIL PROTECTED] Wrote:

| On Thu, 27 Jul 2006 09:17:56 -0700, Carl J. Van Arsdall
| [EMAIL PROTECTED] declaimed the following in comp.lang.python:
|
|  Ah, alright, I think I understand, so threading works well for sharing
|  python objects.  Would a scenario for this be something like a a job
|  queue (say Queue.Queue) for example.  This is a situation in which each
|  process/thread needs access to the Queue to get the next task it must
|  work on.  Does that sound right?  Would the same apply to multiple
|  threads needed access to a dictionary? list?
| 
| Python's Queue module is only (to my knowledge) an internal
| (thread-shared) communication channel; you'd need something else to work
| IPC -- VMS mailboxes, for example (more general than UNIX pipes with
| their single reader/writer concept)
|
|  shared memory mean something more low-level like some bits that don't
|  necessarily mean anything to python but might mean something to your
|  application?
| 
| Most OSs support creation and allocation of memory blocks with an
| attached name; this allows multiple processes to map that block of
| memory into their address space. The contents of said memory block is
| totally up to application agreements (won't work well with Python native
| objects).
|
| mmap()
|
| is one such system. By rough description, it maps a disk file into a
| block of memory, so the OS handles loading the data (instead of, say,
| file.seek(somewhere_long) followed by file.read(some_data_type) you
| treat the mapped memory as an array and use x = mapped[somewhere_long];
| if somewhere_long is not yet in memory, the OS will page swap that part
| of the file into place). The file can be shared, so different
| processes can map the same file, and thereby, the same memory contents.
|
| This can be useful, for example, with multiple identical processes
| feeding status telemetry. Each process is started with some ID, and the
| ID determines which section of mapped memory it is to store its status
| into. The controller program can just do a loop over all the mapped
| memory, updating a display with whatever is current -- doesn't matter if
| process_N manages to update a field twice while the monitor is
| scanning... The display always shows the data that was current at the
| time of the scan.
|
| Carried further -- special memory cards can (at least they were
| where I work) be obtained. These cards have fiber-optic connections. In
| a closely distributed system, each computer has one of these cards, and
| the fiber-optics link them in a cycle. Each process (on each computer)
| maps the memory of the card -- the cards then have logic to relay all
| memory changes, via fiber, to the next card in the link... Thus, all the
| closely linked computers share this block of memory.

This is nice to share inputs from the real world - but there are some hairy
issues if it is to be used for general purpose consumption - unless there are
hardware restrictions to stop machines stomping on each other's memories - i.e.
the machines have to be *polite* and *well behaved* - or you can easily have a
major smash...
A structure has to agreed on, and respected...

 - Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest Way To Loop Through Every Pixel

2006-07-28 Thread H J van Rooyen
Paul McGuire [EMAIL PROTECTED] wrote:

| Even downer-and-dirtier, you could approximate 30 with 32, 59 with 64, and
| 11 with 8, and do bit-shifting instead of multiplying:
|
| def darkness(img,x,y):
| return  (RedVal(img,x,y)  5) + (GreenVal(img,x,y)  6) +
| (BlueVal(img,x,y)  3)
|
|
| -- Paul

*grin* - a man after my own heart! - how do you multiply by ten? - shift, save a
copy, shift twice more and add the copy...

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Fastest Way To Loop Through Every Pixel

2006-07-28 Thread H J van Rooyen

 Paul McGuire [EMAIL PROTECTED] wrote:

| H J van Rooyen [EMAIL PROTECTED] wrote in message
| news:[EMAIL PROTECTED]
|  Paul McGuire [EMAIL PROTECTED] wrote:
| 
|  | Even downer-and-dirtier, you could approximate 30 with 32, 59 with 64,
| and
|  | 11 with 8, and do bit-shifting instead of multiplying:
|  |
|  | def darkness(img,x,y):
|  | return  (RedVal(img,x,y)  5) + (GreenVal(img,x,y)  6) +
|  | (BlueVal(img,x,y)  3)
|  |
|  |
|  | -- Paul
| 
|  *grin* - a man after my own heart! - how do you multiply by ten? - shift,
| save a
|  copy, shift twice more and add the copy...
| 
|  - Hendrik
| 
| Sadly, my timeit results show this saves only a little time, and
| shift-copy-shiftsomemore-and-add is even slower then just doing the original
| floating point multiply.  The biggest win is in prelookup of Image.GetXXX
| functions.
|
| -- Paul

I was not seriously suggesting this for use in python on a pc - its the sort of
rubbish you do on a small embedded machine that has a reduced instruction set
and no multiplier...

- Hendrik



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to force a thread to stop

2006-07-28 Thread H J van Rooyen
Paul Rubin http://[EMAIL PROTECTED] Wrote:


| H J van Rooyen [EMAIL PROTECTED] writes:
|  So on a processor that does not have protected instructions - if an
|  idiot writes something to the following effect :
| 
|  *instructions to disable interrupts*
| 
|  followed by :
| 
|  *instructions that go into an infinite loop AND that make no OS calls*
| 
|  the whole bang shoot stops dead - Reset your machine...
|
| A common recovery mechanism in embedded systems is a watchdog timer,
| which is a hardware device that must be poked by the software every
| so often (e.g. by writing to some register).  If too long an interval
| goes by without a poke, the WDT hard-resets the cpu.  Normally the
| software would poke the WDT from its normal periodic timing routine.
| A loop like you describe would stop the timing routine from running,
| eventually resulting in a reset.

*grin* - Yes of course - if the WDT was enabled - its something that I have not
seen on PC's yet...

- Hendrik



-- 
http://mail.python.org/mailman/listinfo/python-list


Re: How to force a thread to stop

2006-07-27 Thread H J van Rooyen
Carl J. Van Arsdall [EMAIL PROTECTED] wrote:

8


| point).  Its not only important that the threads die, but that they die
| with grace.  There's lots of cleanup work that has to be done when
| things exit or things end up in an indeterminable state.
|
| So, I feel like I have a couple options,
|
|  1) try moving everything to a process oriented configuration - we think
| this would be bad, from a resource standpoint as well as it would make
| things more difficult to move to a fully distributed system later, when
| I get my army of code monkeys.
|
| 2) Suck it up and go straight for the distributed system now - managers
| don't like this, but maybe its easier than I think its going to be, I dunno
|
| 3) See if we can find some other way of getting the threads to terminate.
|
| 4) Kill it and clean it up by hand or helper scripts - we don't want to
| do this either, its one of the major things we're trying to get away from.

8-

This may be a stupid suggestion - If I understand what you are doing, its
essentially running a bunch of compilers with different options on various
machines around the place - so there is a fifth option - namely to do nothing -
let them finish and just throw the output away - i.e. just automate the
cleanup...

- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Tkinter pack Problem

2006-07-27 Thread H J van Rooyen

Simon Forman [EMAIL PROTECTED] wrote:

| I find the Tkinter reference: a GUI for Python under Local links on
| this page http://infohost.nmt.edu/tcc/help/lang/python/tkinter.html to
| be very helpful.  It has a decent discussion of the grid layout
| manager.
| 
| HTH,
| ~Simon

Thanks am checking it out - downloading pdf... - Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Tkinter pack Problem

2006-07-26 Thread H J van Rooyen
Hi,

I am struggling to get the pack method to do what I intend.
I am trying to display user input in a seperate window, along with
a little description of the field, something like this:

 Current entry
Company :   entered co. name
First entry :   entered stuff
The second entry: more entered stuff
Entry number three :  Last entered stuff

This seems so simple - but I have now spent a day or two mucking around -
and no matter what I do with the side, after and anchor parameters,
I just seem to get weird results - I must be doing something terribly stupid,
but I cant see it

So I have boiled the thing down as far as I can. - to an entry window with a
start and quit button,
one entry method, and the display window for the entered content - aside from
displaying, the programme does nothing.

Its doing the same thing on Linux and on Windows

This code should run and illustrate the hassles I am having:

8-start of code section--

#!/usr/bin/python
#   The original of this module is supposed to do an accounting entry -

#   we get the gui stuff

from Tkinter import *

class Entryscreen(Frame):
This screen is used to construct a new Entry.

#   we define the variables we use

des_string = '' # Description of what we want to do
req_string = '' # Prompt string
dis_string = '' # Description of field for display

Company =  New Entry Screen   # we dont have a company yet
Entry_1 = ''# or any entries
Entry_2 = ''
Entry_3 = ''

def start_new(self):
This is the routine that assembles a new record

if self.Company == New Entry Screen:  # if its the first time,

#   we make a new window

show = Tk()
show.title('Accounting entry display window')

#   we get an instance to display results in

self.disp = Showscreen(Current entry,master=show)

#   then we ask for the company:

des_string = Getting the Company 
req_string = Enter the Company for this session
dis_string = 'Company:'
error = self.GetEntry(des_string, req_string, dis_string, self.disp)
self.Company = self.Amount

#   Then or else we ask for entry details

des_string = Getting first entry
req_string = Enter first field
dis_string = First entry:
error = self.GetEntry(des_string, req_string, dis_string, self.disp)

des_string = Getting second entry
req_string = Enter second field
dis_string = The second entry:
error = self.GetEntry(des_string, req_string, dis_string, self.disp)

des_string = Getting third entry
req_string = Enter third field
dis_string = Entry number three:
error = self.GetEntry(des_string, req_string, dis_string, self.disp)

def GetEntry(self, des_string, req_string, dis_string, disp):
Entry routine for one field

line = Entryline(des_string, req_string, dis_string, disp, master=root)
error = line.mainloop()
self.Amount = line.retstring
line.destroy()

def say_bye(self):
print 'Have a nice day, Bye!'
self.quit()

def createWidgets(self):

self.descr = Label(self)
self.descr[text] = self.Company
self.descr[fg] = 'purple'
self.descr['bg'] = 'yellow'
self.descr.pack({'expand': 'yes', 'fill': 'both', side: top})

Start = Button(self)
Start[text] = Start a new entry
Start[fg]   = blue
Start['bg']   = 'green'
Start[command] =  self.start_new
Start.pack({'expand': 'yes', 'fill': 'both', side: left, 'after':
self.descr})

QUIT = Button(self)
QUIT[text] = QUIT
QUIT[fg]   = black
QUIT['bg']   = 'red'
QUIT[command] =  self.say_bye
QUIT.pack({'expand': 'yes', 'fill': 'both', side: left, 'after':
Start})

def __init__(self, master=None):
Frame.__init__(self, master)
self.pack()
self.createWidgets()

class Showscreen(Frame):
This is supposed to show the entries as they occur.

def CreateWidgets(self, Description):

self.descr = Label(self)
self.descr[text] = Description
self.descr[fg] = 'purple'
self.descr['bg'] = 'yellow'
self.descr.pack({'expand': 'yes', 'fill': 'x', side: top, anchor:
n})

def __init__(self, Description, master=None):
Frame.__init__(self,master)
self.pack()
self.CreateWidgets(Description)

class Entryline(Frame):
This asks for an entry from the user and displays the result

retstring = ''

def entryend(self,S):
This gets done on carriage return and is where the hassles
originate

self.retstring = self.estring.get() # get the entered string

self.disp.Amount_des = Label(self.disp)   # and put it into the
display window

Re: Tkinter pack Problem

2006-07-26 Thread H J van Rooyen

Eric Brunel [EMAIL PROTECTED] wrote:

|On Wed, 26 Jul 2006 12:46:39 +0200, H J van Rooyen [EMAIL PROTECTED]
|wrote:
|
| Hi,
|
| I am struggling to get the pack method to do what I intend.
| I am trying to display user input in a seperate window, along with
| a little description of the field, something like this:
|
|  Current entry
| Company :   entered co. name
| First entry :   entered stuff
| The second entry: more entered stuff
| Entry number three :  Last entered stuff
|
|You won't be able to do that kind of layout with pack. This is - quite
|obviously IMHO - a job for grid, since your widgets are arranged in a grid.
|
|According to my experience, pack should only be used for *very* simple
|layouts, such as all widgets in a single row or in a single column. Trying
|to do anything else will very soon end up being a nightmare, with unneeded
|frames everywhere. Learn to use grid and life will be far easier for you.

I can kind of agree with this - If I learnt one thing it was that I can get them
in a column, or a row, or what looks like a weird kind of horizontal hierarchy,
but not what I was looking for...

|
|[snip]
|
|A few comments on your code:
|
| #!/usr/bin/python
| #   The original of this module is supposed to do an accounting entry -
|
| #   we get the gui stuff
|
| from Tkinter import *
|
| class Entryscreen(Frame):
|
|Why do you inherit from Frame? Apparently, you're trying to do a window. A
|Frame is not a window; it's a general-purpose container for widgets. If
|you want to do a window, inherit from Tk (for a main window) or from
|Toplevel (for any other).

No particular reason other than ignorance - the original example I was following
did something like this, and
as it actually produced something that looked to me like it was working I did
not mess with it :-)

What is the best place to get info on all these wonderful things - I have been
trying to come right by reading the module help - but its kind of cryptic... -
like most things its cool as a reminder if you already know what it does...

|
| This screen is used to construct a new Entry.
|
| #   we define the variables we use
|
| des_string = '' # Description of what we want to do
| req_string = '' # Prompt string
| dis_string = '' # Description of field for display
|
| Company =  New Entry Screen   # we dont have a company yet
| Entry_1 = ''# or any entries
| Entry_2 = ''
| Entry_3 = ''
|
| def start_new(self):
| This is the routine that assembles a new record
|
| if self.Company == New Entry Screen:  # if its the first time,
|
| #   we make a new window
|
| show = Tk()
|
|No, we don't. We actually create a whole new tcl/tk interpreter
|environment, completely independent from the one we already have, which
|happens to create a new main window. Doing so is bound to cause problems
|later. If you want to create a new window, instantiate Toplevel.
|

Ok I will try it, thanks.


| show.title('Accounting entry display window')
|
| #   we get an instance to display results in
|
| self.disp = Showscreen(Current entry,master=show)
|
| #   then we ask for the company:
|
| des_string = Getting the Company 
| req_string = Enter the Company for this session
| dis_string = 'Company:'
| error = self.GetEntry(des_string, req_string, dis_string,
| self.disp)
| self.Company = self.Amount
|
| #   Then or else we ask for entry details
|
| des_string = Getting first entry
| req_string = Enter first field
| dis_string = First entry:
| error = self.GetEntry(des_string, req_string, dis_string,
| self.disp)
|
| des_string = Getting second entry
| req_string = Enter second field
| dis_string = The second entry:
| error = self.GetEntry(des_string, req_string, dis_string,
| self.disp)
|
| des_string = Getting third entry
| req_string = Enter third field
| dis_string = Entry number three:
| error = self.GetEntry(des_string, req_string, dis_string,
| self.disp)
|
|This is not important, but why do you always create variables for your
|strings instead of passing them directly? For example, the previous 4
|lines can be written:

The original code actually used the variables as globals ... *ducks*

|
|error = self.GetEntry(Getting third entry, Enter third field, Entry
|number three:, self.disp)
|
|This would shorten your code a lot. And why do you always pass self.disp
|as the last argument? This is an attribute, so using it directly inside
|the GetEntry method is not a problem.

The thing was giving me all sorts of errors when I changed disp from being a
global - It prolly has to do with the bad move of having a second instance of
k  - I messed around and stopped when I got no more errors - could this be what
is really meant by Heuristic Programming

Re: How can get button's name when cursor move over the button ona web page?

2006-07-15 Thread H J van Rooyen
Steve Holden [EMAIL PROTECTED] wrote:

8(snip)-
|Questions nowadays have no idea which groups they belong to. When *I*
|was a lad questions had to know their place. A question that appeared in
||the wrong group would be torched with flames that could be guaranteed to
|burn through asbestos. But you tell these young people and they just
|don't believe you.
|
|A Yorkshireman

- You were lucky...
 - in *my* day, we did not even have fuel for flames, because we had no
internet
   We actually had to use the local library - and *horrors* - you had to learn
to read, and to solve your own queries...
   These youngsters just don't know how easy they have it...

- Hendrik van Rooyen (not a Yorkshireman)




-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python for Embedded Systems?

2006-07-15 Thread H J van Rooyen

Carl J. Van Arsdall [EMAIL PROTECTED] Wrote:
To: python-list@python.org
Sent: Friday, July 14, 2006 7:36 PM
Subject: Re: Python for Embedded Systems?


| Grant Edwards wrote:
|  On 2006-07-14, Jack [EMAIL PROTECTED] wrote:
| 
|  Is there a Python packaging that is specifically for
|  embedded systems? ie, very small and configurable so the
|  user gets to select what modules to install?
| 
|  For Linux-based embedded systems in particular?
| 
|  I'm thinking of running it on the Linksys's Linux-based open
|  source router WRT54G. It has 4MB flash and 16MB RAM. I think
|  another model has 16MB flash. Any possibilities of running
|  Python on these systems?
| 
| 
|  A few years back there was a deeply embedded python project,
|  but it's been dead for quite a while:
| 
|   http://www.tucs.fi/magazin/output.php?ID=2000.N2.LilDeEmPy
| 
http://mail.python.org/pipermail/python-announce-list/1999-August/000157.html
| 
| 
| This raises a good question.  Is there a need for python to change
| somewhat to work better in an embedded profile?  Are there many people
| in the community interested in using python for embedded projects?
|

I for one would be interested in using it - if it can be made small enough - I
do not see it helping me with the nitty gritty of getting a system running on
bare metal, as the low level stuff in a small system is still best done in
assembler - but if there is a display and some sort of keyboard and you can
stick to character based stuff it will ease the application part of the work a
lot - its a natural for doing things like logging and simple transactions - and
if the hardware is strong enough to get IP running - then it will open up the
systems to be web based...

It will also be of use as you could prototype on a PC - emulators and simulators
of small systems are mostly a pain as it takes a lot of effort to describe the
actual hardware before these are useful...

Small in this context is an eight bit processor (like an 80x1 | x = 3, 5 )
with some tricks done in the hardware to expand the native 16 bit address space
to address say half a Meg of battery backed up static ram as data space, with
about 62k of code space available for the interpreter and the custom OS to run
in - (Harvard architecture, not von Neumann) - These processors have lately been
improved from the original about half a MIP to now give sustained performance of
better than 10 MIPS - So they may just be able to cripple along doing the
interpreting - But its *Quite a Challenge* to fit the interpreter in, though...

It is easily possible to expand these processor's address space to 24 bits -
that is 16 Meg - and it may be a better approach to make a 'Virtual Processor'
to run the python stuff - is there a definition for that sort of thing, akin to
Java's Virtual Processor? - It would be a better approach, as the resultant
higher level work would be more portable - to port to another class of
processor, you need merely write the Virtual Machine - in whatever Language
takes your fancy...

What is the minimum set of instructions and structure needed to make a
simplistic Python? - does anybody know?

Might just be a pipe dream...

- Hendrik van Rooyen


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Python is fun (useless social thread) ;-)

2006-06-19 Thread H J van Rooyen
Bruno wrote:

8(snip)--

| The answer is 42. That's all you need to know.


Right on, Ford Prefect !!!

What's for Lunch?

- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: a good programming text editor (not IDE)

2006-06-17 Thread H J van Rooyen
Tim Chase wrote:

|  No need to argue. I started with vim, and finally switched to
|  emacs less than one year later.
|
| Both are very-much-so good editors.  I made the opposite switch
| from emacs to vim in less than a year.  Both are good^Wgreat
| editors, so one's decision to use one over the other is more a
| matter of working style.  I don't grok LISP, and just never felt
| at home in emacs, despite all the power I could see that was
| there.  I grok vim (and its similar power/extensibility), so I
| migrated to it.  I have to laugh at the whole holy-war thing, as
| it's somewhat like arguing about a favorite color.  But blue is
| so better than green!  The sky is blue!  Nuh, uh!  Green is far
| better than blue!  Grass is green! (okay, here in Texas, that
| doesn't always hold as true...maybe personality #2 should be
| arguing for brown instead).
|
| My best friend is an emacs user, and I'm a vimmer...it doesn't
| come between us. :)

You guys are not gonna believe this - I keep a low grade PC specially so that I
can do my programming with Brief  (yes the one by Underware) - and yes I know
Emacs has a so called *crisp* emulator - but IMNSHO it sucks!

I like the macros, I do some stuff with the macro language, and as a mostly
assembler programmer, I adore the way it copies and pastes columns with minimal
keystrokes

And I switch between buffers (different files - modules in Python ) - with an
alt n or alt - .

and worse - like the confirmed Vi or Emacs user - the problem is that you get
used to it, and ya dont wanna change...

- Hendrik

I wish I could run this on my Linux box

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Intermittent Failure on Serial Port (Other thread code)

2006-06-13 Thread H J van Rooyen
I would like to publicly thank Serge Orloff for the effort he has put in so far
and his patience...
He is a Scholar and a Gentleman.

Serge Orloff wrote:

| H J van Rooyen wrote:
|
|  Note that the point of failure is not the same place in the python file, but
it
|  is according to the traceback, again at a flush call...
|
| Yes, traceback is bogus. Maybe the error is raised during garbage
| collection, although the strace you've got doesn't show that. The main
| reason of the failure seems to be a workaround in python's function
| new_buffersize, it doesn't clear errno after lseek and then this errno
| pops up somewhere else. There are two places I can clearly see that
| don't clear errno: file_dealloc and get_line. Obviously this stuff
| needs to be fixed, so you'd better file a bug report.

Ouch! - I am new in this neck of the woods - what are the requirements for
something like this and where should I send it to so its useful? - so far its so
very vague in my mind that I am not sure that I can actually tell someone else
properly what's wrong - except for a it does not work bleat which is not very
illuminating...

| I'm not sure how
| to work around this bug in the meantime, since it is still not clear
| where this error is coming from. Try to pin point it.

I will put in a lot of try - except stuff looking for this errno 29 and see what
comes up and where.
Not sure if this will catch it but it may give a clue..

|For example, if
| your code relies on garbage collection to call file.close, try to close
| all files in your program explicitly. It seems like a good idea anyway,
| since your program is long running, errors during close are not that
| significant. Instead of standard close I'd call something like this:
|
| def soft_close(f):
| try:
| f.close()
| except IOError, e:
| print stderr, Hmm, close of file failed. Error was: %s %
| e.errno

As you remark - the code is long running - its supposed to work for ever and
come back up again if the power has failed - so for now the serial port is never
explicitly closed - I open and close the other files as I use them to try to
make sure the data is written to disk instead of just cached to memory.  I will
put this sort of thing in everywhere now to try and isolate whatever it is that
is biting me, not only on the close statements.

|
|  The close failed is explicable - it seems to happen during closedown, with
the
|  port already broken..,
|
| It is not clear who calls lseek right before close. lseek is called by
| new_buffersize that is called by file.read. But who calls file.read
| during closedown?

When I said closedown - I meant whatever the system does after the exception was
raised - I have not yet gotten as far as writing a clean close... - so far I am
concentrating on the polling protocol, to safely get the data from the readers
to the disk - port to file hence the name :-)

Now there is another thread running - it accesses files, (disk and a fifo to
trigger the disk write) but not the serial port - I have not laid any stress on
it because I thought it was irrelevant, but now I am not so sure - the code
follows below -

So question - is this error number a process global thing or is it local to a
thread or an object? - it could be this thread that calls read while the other
one is in the process of dying after the exception - it should not access the
port, though, although it repetitively reads a fifo... - come to think of it -
it could be this thread that first raises the ESPIPE for all I know (that is if
its global and not thread specific)...

def maintain_onsite(fifoname, filename):
 Here we keep track of who is in, and who out of the site

 j = thread.get_ident()
 print 'New Thread identity printed by new thread is:', j
 pfifo  = open(fifoname,'r',1)# Reading, line buffered
 unblock(pfifo)# call some magic

 global on_site#use top level dictionary to avoid a lot of copying

 s = 
 d = {}

 while True:
  try:
   s = pfifo.readline()
  except IOError:
   time.sleep(1)
   continue
  if s == '':
   continue
  if s != 'goon\n':  # see if we got a go on signal
   continue
  d = on_site# make a copy of the on site dictionary
  pfile = open(filename,'w',1)   # The file of people on site
  for x in d:
   pfile.write(x + ' ' + d[x] + '\n') # rewrite it - a bit brute force...
  pfile.close()
  s = '' # clean out the receive string again

Here is unblock code:

# Some magic to make a file non blocking - from the internet

def unblock(f):
Given file 'f', sets its unblock flag to true.

fcntl.fcntl(f.fileno(), fcntl.F_SETFL, os.O_NONBLOCK)


- Hendrik


-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Intermittent Failure on Serial Port

2006-06-12 Thread H J van Rooyen

Serge Orlof wrote:

| H J van Rooyen wrote:
|  Serge Orloff wrote:
| 
|  | H J van Rooyen wrote:
|  |  Traceback (most recent call last):
|  |File portofile.py, line 232, in ?
|  |  ret_val = main_routine(port, pollstruct, pfifo)
|  |File portofile.py, line 108, in main_routine
|  |  send_nak(port, timeout)  # so bad luck - comms error
|  |File /home/hvr/Polling/lib/readerpoll.py, line 125, in send_nak
|  |  port.flush()
|  |  IOError: [Errno 29] Illegal seek
|  |  close failed: [Errno 29] Illegal seek
|  | 
|  |
|  |
|  |  Where can I find out what the Errno 29 really means?
|  |  Is this Python, the OS or maybe hardware?
|  |
|  | It is from kernel: grep -w 29 `locate errno`
|  | /usr/include/asm-generic/errno-base.h: #define   ESPIPE  29
|  |  /* Illegal seek */
|  |
|  | man lseek:
|  |
|  | ERRORS:
|  | ESPIPE fildes is associated with a pipe, socket, or FIFO.
|  |
|  | RESTRICTIONS:
|  | Linux  specific  restrictions:  using  lseek  on  a  tty device
|  | returns ESPIPE.
| 
| 
|  Thanks for the info - so the Kernel sometimes bombs me out - does anybody
know
|  why the python flush sometimes calls lseek?
|
| I thought it was your own flush method. If it is file.flush method that
| makes the issue more complicated, since stdlib file.flush doesn't call
| lseek method. I suggest you run your program using strace to log system
| calls, without such log it's pretty hard to say what's going on. The
| most interesting part is the end, but make sure you have enough space
| for the whole log, it's going to be big.

Thanks - I will research and use the strace - havent used it before - I have
about 30 gig disk space left...
Trouble is that the silly thing works for anything from some hours to some days
before it falls over - ugly...
Will bleat again when I have some more results...

In the meantime I have a datascope attached to the line, and it appears as if it
was on the point of sending a nak in response to a perfectly well formed
message - almost as if either an interrupt was missed - unlikely at 9600 baud
and a pentium 3 at some 2 GHz - or there is a weird hardware error - also
unlikely - hardware normally just breaks, does not work for millions for chars
and miss one... - I dont like the implication...

I also dont really understand the second reference - to a close that failed -
anyway we have to wait for the trace...


- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Intermittent Failure on Serial Port (Trace Result)

2006-06-12 Thread H J van Rooyen

8-- (snip)

old fail:

| |  |  Traceback (most recent call last):
| |  |File portofile.py, line 232, in ?
| |  |  ret_val = main_routine(port, pollstruct, pfifo)
| |  |File portofile.py, line 108, in main_routine
| |  |  send_nak(port, timeout)  # so bad luck - comms error
| |  |File /home/hvr/Polling/lib/readerpoll.py, line 125, in send_nak
| |  |  port.flush()
| |  |  IOError: [Errno 29] Illegal seek
| |  |  close failed: [Errno 29] Illegal seek
| |  | 
| |  |
| |  |
| |  |  Where can I find out what the Errno 29 really means?
| |  |  Is this Python, the OS or maybe hardware?
| |  |
| |  | It is from kernel: grep -w 29 `locate errno`
| |  | /usr/include/asm-generic/errno-base.h: #define   ESPIPE  29
| |  |  /* Illegal seek */
| |  |
| |  | man lseek:
| |  |
| |  | ERRORS:
| |  | ESPIPE fildes is associated with a pipe, socket, or FIFO.
| |  |
| |  | RESTRICTIONS:
| |  | Linux  specific  restrictions:  using  lseek  on  a  tty device
| |  | returns ESPIPE.
| | 
| | 
| |  Thanks for the info - so the Kernel sometimes bombs me out - does anybody
| know
| |  why the python flush sometimes calls lseek?
| |
| | I thought it was your own flush method. If it is file.flush method that
| | makes the issue more complicated, since stdlib file.flush doesn't call
| | lseek method. I suggest you run your program using strace to log system
| | calls, without such log it's pretty hard to say what's going on. The
| | most interesting part is the end, but make sure you have enough space
| | for the whole log, it's going to be big.

8 (snip)

New Konsole output:

../logs/composite/rawlog
Pipe exists already
we get here - thread identity is: 1079298992
New Thread identity printed by new thread is: 1079298992
we get here too
5 0123456789012345 Sefie Sewenstein is in
5 0270021348 Error record - catch her, catch him
3 9E0049592001 Antonie de Kompaan is in
2 8A0870BEDE01 Bertus Bierdrinker is in

At 2006/06/12 10:03:20  The following people were in:

0123456789012345 Sefie Sewenstein
9E0049592001 Antonie de Kompaan
8A0870BEDE01 Bertus Bierdrinker

Traceback (most recent call last):
  File portofile.py, line 232, in ?
ret_val = main_routine(port, pollstruct, pfifo)
  File portofile.py, line 90, in main_routine
s, ret_val  = poll_one(port, addy, dtype, timeout)  # poll one reader
  File /home/hvr/Polling/lib/readerpoll.py, line 81, in poll_one
port.flush()# make sure it goes
IOError: [Errno 29] Illegal seek
close failed: [Errno 29] Illegal seek

-end of Konsole output 

We have the whole of that session captured by strace - some 45 Mb of it.

Note that the point of failure is not the same place in the python file, but it
is according to the traceback, again at a flush call...

The close failed is explicable - it seems to happen during closedown, with the
port already broken..,

Here is the the last bit of the trace - I cant figure out who or what calls the
lseek on file 3 to get the ESPIPE result...

There are some comments added to the trace and the code below like this
[comment]

--strace output (tail
of) ---

gettimeofday({1150099428, 256932}, NULL) = 0
gettimeofday({1150099428, 257043}, NULL) = 0
gettimeofday({1150099428, 311401}, NULL) = 0
futex(0x80a8918, FUTEX_WAKE, 1) = 0
futex(0x80a8918, FUTEX_WAKE, 1) = 0
write(3, \6~7\1, 4)   = 4  [This was last
write and it came out on port]

[I would have expected the flush here soon]

[but it does not seem to be a system call]
gettimeofday({1150099428, 409245}, NULL) = 0 [this looks like the start
of waiting for the echo]
gettimeofday({1150099428, 409350}, NULL) = 0
futex(0x80a8918, FUTEX_WAKE, 1) = 0
read(3, 0x4003a000, 4096)   = -1 EAGAIN (Resource temporarily
unavailable)
gettimeofday({1150099428, 409821}, NULL) = 0
futex(0x80a8918, FUTEX_WAKE, 1) = 0
futex(0x80a8918, FUTEX_WAKE, 1) = 0
read(3, 0x4003a000, 4096)   = -1 EAGAIN (Resource temporarily
unavailable)
gettimeofday({1150099428, 411038}, NULL) = 0
futex(0x80a8918, FUTEX_WAKE, 1) = 0
read(3, 0x4003a000, 4096)   = -1 EAGAIN (Resource temporarily
unavailable)
gettimeofday({1150099428, 411530}, NULL) = 0
futex(0x80a8918, FUTEX_WAKE, 1) = 0
read(3, 0x4003a000, 4096)   = -1 EAGAIN (Resource temporarily
unavailable)
gettimeofday({1150099428, 412005}, NULL) = 0
futex(0x80a8918, FUTEX_WAKE, 1) = 0
read(3, 0x4003a000, 4096)   = -1 EAGAIN (Resource temporarily
unavailable)
gettimeofday({1150099428, 412478}, NULL) = 0
futex(0x80a8918, FUTEX_WAKE, 1) = 0
read(3, 0x4003a000, 4096)   = -1 EAGAIN (Resource temporarily
unavailable)
gettimeofday({1150099428, 412950}, NULL) = 0
futex(0x80a8918, FUTEX_WAKE, 1) = 0
read(3, 0x4003a000, 4096)   = -1 EAGAIN 

Intermittent Failure on Serial Port

2006-06-10 Thread H J van Rooyen
Hi All,

I am writing a polling controller for an RS-485 line that has
several addressable devices connected.
It is a small access control system.
All is well- the code runs for anything from three hours to three days, then
sometimes when I get a comms error and have to send out a nak character, it
fails hard...

The traceback below pops up. - the first lines are just some debug prints.
and the four records show reader number, id number, name...

___start of Konsole Messages __

/dev/ttyS0 set to 9600 sane cread raw -echo
../logs/composite/rawlog
Pipe exists already
we get here - thread identity is: 1079298992
New Thread identity printed by new thread is: 1079298992
we get here too
5 0123456789012345 Sefie Sewenstein is in
2 DE085ABF8A01 Error record - catch her, catch him
2 8A0870BEDE01 Bertus Bierdrinker is in
5 0123456789012345 Sefie Sewenstein is out
Traceback (most recent call last):
  File portofile.py, line 232, in ?
ret_val = main_routine(port, pollstruct, pfifo)
  File portofile.py, line 108, in main_routine
send_nak(port, timeout)  # so bad luck - comms error
  File /home/hvr/Polling/lib/readerpoll.py, line 125, in send_nak
port.flush()
IOError: [Errno 29] Illegal seek
close failed: [Errno 29] Illegal seek

___end of Konsole Messages ___


The additional thread referred to is used to maintain a file of
people on the premises,- it is not relevant to this,
as it just writes out a global dictionary when
something has changed, and it works quite merrily...

Some of what I think are the relevant code snippets:

This one works all the time, as I send out an ack on the
succesful receipt of a message from one of the readers, and
I have not seen it fail yet:

def send_ack(port, timeout):
Routine to send out an ack on port

ack_string = ack # Ascii ack = '\x06'
s = ''

port.write(ack_string)
port.flush()
flush_out(port,timeout)# eat the echoed ack

This one is called after a comms error, and sometimes falls over in the above
manner...

def send_nak(port, timeout):
Routine to send out a nak on port

nak_string = nak # Ascii nak = '\x15'
s = ''

port.write(nak_string)
port.flush()
flush_out(port, timeout)   # eat the echoed nak


# here we read to end, to flush a port buffer

def flush_out(file, time_out):
Reads the port till no more chars come in for a while

start_time = time.time()
s = ''
while (time.time() - start_time  time_out):
s, ret_val = read_char(file, s)
if ret_val == 0: # if there is input...
start_time = time.time()


#   We make a function to read a char of file data

def read_char(file, s):
Reads file data returns string, ret_val is 0 on success, 1 for KbdInt, 2
no input.

ret_val = 0# No error yet
k = '' # Nothing read yet
try:
k = file.read(1)  # read one char in as a string
except KeyboardInterrupt:
print \n^C - Returning to Shell - Error is:, KeyboardInterrupt
ret_val = 1# ^C while waiting for input
return k, ret_val  # go out on error
except IOError:
ret_val = 2# IOError on input - no record available
return s, ret_val  # so no extra chars
if k == '': # empty string is nfg
ret_val = 2
return s, ret_val  # so no extra chars
s = s + k # something to add in to passed buffer
return s, ret_val   # ok exit no error


Note that the file is unblocked with some magic from fcntl module...
The file is the serial port /dev/ttyS0
There is hardware connected to the port that has the effect of a loopback - you
hear what you say..

Out of the box distribution - SuSe 10:

Python 2.4.1 (#1, Sep 13 2005, 00:39:20)
[GCC 4.0.2 20050901 (prerelease) (SUSE Linux)] on linux2
Type help, copyright, credits or license for more information.


Where can I find out what the Errno 29 really means?
Is this Python, the OS or maybe hardware?

Any Ideas or suggestions will be appreciated

(I am doing this via email - so I am not on line all the time- so my responses
may be slow...)

- Hendrik van Rooyen

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Intermittent Failure on Serial Port

2006-06-10 Thread H J van Rooyen

Serge Orloff wrote:

| H J van Rooyen wrote:
|  Traceback (most recent call last):
|File portofile.py, line 232, in ?
|  ret_val = main_routine(port, pollstruct, pfifo)
|File portofile.py, line 108, in main_routine
|  send_nak(port, timeout)  # so bad luck - comms error
|File /home/hvr/Polling/lib/readerpoll.py, line 125, in send_nak
|  port.flush()
|  IOError: [Errno 29] Illegal seek
|  close failed: [Errno 29] Illegal seek
| 
|
|
|  Where can I find out what the Errno 29 really means?
|  Is this Python, the OS or maybe hardware?
|
| It is from kernel: grep -w 29 `locate errno`
| /usr/include/asm-generic/errno-base.h: #define   ESPIPE  29
|  /* Illegal seek */
|
| man lseek:
|
| ERRORS:
| ESPIPE fildes is associated with a pipe, socket, or FIFO.
|
| RESTRICTIONS:
| Linux  specific  restrictions:  using  lseek  on  a  tty device
| returns ESPIPE.


Thanks for the info - so the Kernel sometimes bombs me out - does anybody know
why the python flush sometimes calls lseek?

- Hendrik

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: python vs perl lines of code

2006-05-24 Thread H J van Rooyen

on Friday, May 19, 2006 11:26 PM
[EMAIL PROTECTED] wrote:

| All I would ask is what objective evidence does either of actually
| have?  How can you know?  What is a fair way to even count line
| numbers?  From there how do we begin to objectively measure software
| quality?  That's why this discussion interests me, and why I don't
| understand why you are so adamant it doesn't work.  I'll agree that I
| have never seen line count/char count type data used for anything other
| than marketing swill and kitty litter.  Doesn't mean it can't be used.
| But first things first... and this one I think is solvable - their has
| got to be an equitable way to count how much code was written - maybe
| it isn't lines maybe it is.  In truth, since you are so opposed to the
| idea, I'd be curious if you can think of a way to measure the quantity
| of code objectively?  ANd that's it - not can we make a qualitative
| statement beyond that.  But simply can we quanitfy the amount of code
| in some fashion that allows a reasonable comparison?

This is a difficult question -  one way to measure - more or less objectively -
is to somehow figure out how many machine instructions (on some standard
machine - Turing?) would be generated by the code

Even that won't tell us much - cos it will favour inline code as somehow
heavier than looping code...

Now we know that inline code is faster on most machines, and looping code is
more compact, - so how to say what is best?

And this only covers what you computer scientists call the procedures or
methods - the actual instructions that are executed by the machine -  how is
the memory space used to be measured and factored in?  - and the running stack
space needed?  - specially in the case of recursions

And then how do you handle an interpreted language vs a compliled language - do
you count the machine instructions of the interpreter, or only the ones actually
executed? - and the memory consumed by the interpreter?. - And if you count
the interpreter, why not the compiler?...

Not simple, not easy - in fact it's a minefield

- Hendrik van Rooyen

-- 
http://mail.python.org/mailman/listinfo/python-list


The best way of calculating and adding a block check character to a string

2006-05-14 Thread H J van Rooyen



Hi All

I am new to this language, 
and in using it to drive a serial port, I need to calculate classic block check 
characters - for the veterans amongst you - think "Burroughs Poll Select" or 
"Uniscope"...

This is a program fragment 
that puts the string in an array of Bytes - is there a better way to do this 
job? - the annotated action starts after the ascii definitions of the 
first 32 control characters...


# some ascii control character values defined
nul = '\x00' # null char
soh = '\x01' # start of header
stx = '\x02' # start of text
etx = '\x03' # end of text
eot = '\x04' # end of transmission
enq = '\x05' # enquiry
ack = '\x06' # ack
bel = '\x07' # bell char
bs = '\x08' # backspace
ht = '\x09' # horizontal tab
lf = '\x0a' # line feed - linux newline
vt = '\x0b' # vertical tab
ff = '\x0c' # form feed
cr = '\x0d' # carriage return
so = '\x0e' # shift out
si = '\x0f' # shift in
dle = '\x10' # data link escape
dc1 = '\x11' # data control 1 - aka xon
dc2 = '\x12' # data control 2 
dc3 = '\x13' # data control 3 - aka xoff
dc4 = '\x14' # data control 4
nak = '\x15' # negative acknowledgement
syn = '\x16' # sync char
etb = '\x17' # end of transmission block
can = '\x18' # cancel
em = '\x19' # end of message
sub = '\x1a' # sub
esc = '\x1b' # escape
fs = '\x1c' # field separator
gs = '\x1d' # group separator
rs = '\x1e' # record separator
us = '\x1f' # unit separator


# some strings defined

poll = soh + 'P' + 'A' + stx + etx # rudimentary poll string 
bcc = nul
# here starts the trouble:

ar = array.array('B', poll)

bccint = ar[0] # this is prolly dicey - what type and how big is this?

for x in ar[1:]:
 bccint = bccint ^ x # this works, but is it the best 
way?

print repr(bccint)

ar.append(bccint)

# this seems so left-handed - we make a string, then we put it in an 
array,
# then we iterate over the array elements to calculate the
# bcc (block check character), then we add it to the array - then we 
should
# really make it all a string again to write it to the port...
# it would be nice to be able to write:
# nul = '\x00'
# bcc = nul
# poll = "some arbitrary string"
# bcc = bcc ^ (x for x in poll[0:]) # calculate and
# poll = poll + bcc # add the bcc to the string
# port.write(poll) # and write the lot to the port
# port.flush()
# and on the way in:
# numchars = 5 # some magic number depending on what we are expecting 
back
# response = port.read(numchars) # or a more complicated char at a time 
function
# bcc = nul
# bcc = bcc ^ (x for x in response[0:])
# if bcc != nul:
#  error_routine(response)
# so we would stay working with strings - the stuff from the port
# coming in is a string, and we need a string to write again...
# *grin* but of course the xor and strong typing won't allow the
# string - to say nothing of the iterator...

# here is a loop, demonstrating getting an arbitrary lf terminated string 
in,
# and writing the fixed one with a bcc tagged on out as a response, along
# with some debug printing.
s = esc + '@' + esc + 'v' + lf # the line we are searching for

while True:
 try:
  buffer = port.readline() # read in as a 
string, (unblocked)
except KeyboardInterrupt:
  print "\n^C - Returning to Shell - 
Error is:", KeyboardInterrupt
ret_val = 1 # ^C while 
waiting for input
return buffer, ret_val # go 
out on error
except IOError:
 continue # IOError on input - no 
record available
 if buffer == '': # empty string is rubbish - ignore it
  continue
rawfile.write(buffer) # Keep the record as read
 print repr(buffer) # show how python sees it
 print repr(s) # show what our target looks like
 if s == buffer:
  print 'Bingo !!!'
  ar.tofile(port) # luckily there is this 
method,
  port.flush() # so we don't have to 
convert back to string...

This lot was cut and pasted from the 
little test program Iam using to debug the port stuff -there may be 
tab issues - the question I suppose has to do with the types that the xor 
supports, andI suppose I amsaying that it would be nice if a single 
byte string (also from an iterator) would be supported by the xor operator... ( 
maybe a single char string...there's a difference between ascii and 
unicode...)
Asmy programstands it 
works, but it seems long - winded and ugly
- Hendrik van 
Rooyen
-- 
http://mail.python.org/mailman/listinfo/python-list