Background: To make you understand why I did as I did, a small explanation of the surrounding application is required.
As you correctly pointed out, this is a module for a bigger application that uses Telnet to extract information and execute commands on some hardware devices (in this case Routers). This application is not timecritical due to it's usage, but some optimization I am planning.
Main app: The main application has a GUI using Tk module. The main thread handles all user input, while all the other threads handles Telnet sessions that is connected to hardware devices. Every thread has its presentation in its own window in main GUI (not always visible though). So the application helps the user to command several devices at the same time.
You might think, why not using fork? Well I thought threads would work fine and had more potentials.
Anyway, all logging from the devices is presented in a textwidget. The Telnet-threads should also notify the user if timeouts occur and by their progress. Thats isn't implemented yet. Tk and threads does not go well together so I am going to supply the threads with callback-references to update methods in my GUI app.
Now to answering a few questions you had.
The Update() method is not my final version, just a quick one I wrote to test my app. It had to deliver the Telnet-communication log (stored in $var)in a line-by-line style so it looks like the output you'd get on a terminal if you manually did this. As I mentioned above, it delivers those lines to a callback method in my GUI. Then the callback function inserts the lines into my textwidget.
I wrote to STDOUT to be able to test it without the GUI present, so that is not my intension at all.
You said that I should clear $var, but I can't because I want to save the whole comm-log to file when execution finishes.
One solution is to extract substrings of $var and use that instead. So you know, it didn't feel right to me either with the re-processing lines. It will have no or little effect on the general performance of the program but I would never have it there anyway.
About using a single Update() thread sounds good, think I will use that advice. Did not know that open could be used for "in memory files" so I'll go for that too. Using the main thread to use open() was also my intension so that I'm going to do.
Instead of use as you pointed out, a require in get_connection() is better. I suppose it stays in memory (as you explained earlier) so that I don't need to repeat it in other methods.
In reply to Re^4: Problem with using threads with modules.
by tele2mag
in thread Problem with using threads with modules.
by tele2mag
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |