如何在Matlab中处理MySQL关闭?
大家好
- 我正在编写一个程序,可以在 Matlab 上解析和清理从一个数据库到另一个数据库的大量数据,并从 MySQL 进行查询。这将连续运行,因为新数据每分钟进入第一个数据库,被清理,并在下一个数据点进入之前放入干净的数据库。我想知道在这个过程中,我如何解释两件事。
- 每三个晚上 MySQL 就会关闭一次以进行备份。我希望我的程序在发生这种情况时暂停,并在备份时恢复。我四处寻找解决方案,但似乎找不到解决方案。
允许用户终止该程序。我已经将范围缩小到要么考虑 ctrl+c 杀死,要么创建一个 GUI 来完成它。你们都认为哪种策略更好?
预先感谢您在此事上的时间和帮助。
Greetings all-
I'm writing a program that parses and cleans a lot of data from one database to another on Matlab, querying from MySQL. This would run continuously, as new data come into the first db every minute, are cleaned, and put to the clean db before the next data point comes in. I was wondering how, during this process, I could account for two things...
Every three nights MySQL is shutdown for backup. I'd like my program to pause when this happens, and resume when its back up. I've looked around for a solution, and can't seem to find one for this.
Allow a user to kill the program. I've narrowed this down to either accounting for a ctrl+c kill, or creating a GUI to do it. Which do you all think would be the better strategy?
Thanks in advance for your time and help on this matter.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 TIMER 与 GUI 一起使用。
首先,创建一个带有两个切换按钮的 GUI -“暂停”和“取消”。当程序启动时,启动 GUI 并捕获其句柄。将此句柄传递给计时器对象。每当计时器对象设置为执行时,它应该设置 “暂停”按钮的“值”属性为 1,并在计划维护结束时将其设置回 0。同时,我认为运行 while 循环的程序应该检查暂停按钮值的每次迭代。如果按下该按钮(即其值为 1),程序不应尝试访问数据库。如果释放按钮,程序应该正常运行。
当程序检查按下的暂停按钮时,它还应该检查按下的“取消”按钮。如果按下该按钮,该函数应该
中断
循环并正常退出。在 GUI 中,您还可以设置 closeRequestFcn ,其中会弹出一个对话框,询问用户是否确实要退出正在运行的数据库程序。如果用户选择“是”,则隐藏 GUI (
set(guiHandle,'Visible',false)
) 并“按”取消按钮,以便程序可以退出。当您关闭 Matlab 而不先停止程序时,closeRequestFcn 也会执行。这可以帮助您避免意外关闭 Matlab 并因此意外终止进程。Use a TIMER together with a GUI.
First, create a GUI with two toggle buttons - 'pause' and 'cancel'. When your program starts, launch the GUI and capture its handle. Pass this handle to the timer object. Whenever the timer object is set to execute, it should set the 'Value' property of the 'pause'-button to 1, and at the end of the scheduled maintenance set it back to 0. Meanwhile, your program which runs, I assume, a while loop, should check at every iteration for the value of the pause button. If the button is pressed (i.e. its value is 1), the program should not try and access the database. If the button is released, the program should run as normal.
When the program checks for a pressed pause button, it should also check for a pressed 'cancel' button. If that button is pressed, the function should
break
the loop and gracefully exit.In the GUI, you can also set a closeRequestFcn, where you have a dialog pop open to ask whether the user really wants to quit the running database program. If the user chooses 'yes', hide the GUI (
set(guiHandle,'Visible',false)
) and "press" the cancel button, so that the program can exit. The closeRequestFcn will also execute when you close Matlab without having stopped the program first. This can help you avoid accidentially closing Matlab and thus accidentially killing your process.