Skip to content

Commit e901db4

Browse files
committed
#18 - autoflush processes for dirty exit
It is possible that TagUI processes (main TagUI, integration background processes - SikuliX, Chrome, Chrome browser) are not exited cleanly under certain conditions. For eg, if user Ctrl+C to kill a TagUI for Python script, or if user forgets to use close() to gracefully close off the running processes. These dead processes have insignificant impact to TagUI for Python functionality. However they can cause unnecessary drain on battery and CPU cycles. Raising this issue to make a commit that runs a TagUI script that flush all TagUI-related processes. This will be run within init() so that an accidental Ctrl+C or forgetting to close() allows immediate resumption of use by relaunching Jupyter notebook or Python interactive shell or Python script, and using init(). Placing within close() is meaningless for the scenarios where dead processes happen.
1 parent b4f3728 commit e901db4

File tree

4 files changed

+21
-12
lines changed

4 files changed

+21
-12
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# TagUI for Python
44

5-
[**Use Cases**](#use-cases) | [**API Reference**](#api-reference) | [**About**](#about) | [**v1.5**](https://github.com/tebelorg/TagUI-Python/releases)
5+
[**Use Cases**](#use-cases) | [**API Reference**](#api-reference) | [**About**](#about) | [**v1.6**](https://github.com/tebelorg/TagUI-Python/releases)
66

77
![TagUI for Python demo in Jupyter notebook](https://raw.githubusercontent.com/tebelorg/Tump/master/tagui_python.gif)
88

sample.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
# use pip install tagui to install TagUI for Python
1+
# TagUI for Python's simple, expressive and powerful API makes digital automation fun and easy!
2+
# pip install tagui to install TagUI for Python, pip install tagui --upgrade for latest version
3+
4+
# to use in Jupyter notebook, Python script or interactive shell
25
import tagui as t
36

47
# use init() to start TagUI, it autoruns setup() to download TagUI
@@ -32,7 +35,7 @@
3235
t.snap('logo', 'logo.png')
3336

3437
# another example of interacting with a web page
35-
# include http:// or https:// in URL parameter
38+
# do include http:// or https:// in URL parameter
3639
t.url('https://duckduckgo.com')
3740
t.type('search_form_input_homepage', 'The search engine that doesn\'t track you.')
3841
t.snap('page', 'duckduckgo.png')
@@ -45,9 +48,9 @@
4548
# in above web automation example, web element identifier can be XPath selector, CSS selector or
4649
# attributes id, name, class, title, aria-label, text(), href (in decreasing order of priority)
4750

48-
# TagUI also supports visual element identifier using .png or .bmp image snapshot
51+
# also supports visual element identifier using .png or .bmp image snapshot
4952
# representing the UI element (can be on desktop applications or web browser)
50-
# for eg t.click('start_menu.png'), t.type('username_box.png[enter]', 'Sonic')
53+
# for eg t.click('start_menu.png'), t.type('username_box.png', 'Sonic')
5154

5255
# image transparency (0% opacity) is supported, ie images with empty sections
5356
# t.read('image_preview_frame.png'), t.snap('application_window_frame.png')
@@ -57,5 +60,3 @@
5760

5861
# another eg is limits of area of interest x1, y1, x2, y2 for read() and snap()
5962
# t.read(200, 200, 600, 400), t.snap(200, 200, 600, 400, 'results.png')
60-
61-
# TagUI's simple, expressive and powerful API makes digital automation fun and easy!

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
setup(
44
name='tagui',
5-
version='1.5.0',
5+
version='1.6.0',
66
py_modules=['tagui'],
77
author='Ken Soh',
88
author_email='[email protected]',

tagui.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""INTEGRATION ENGINE FOR TAGUI PYTHON PACKAGE ~ TEBEL.ORG"""
22
__author__ = 'Ken Soh <[email protected]>'
3-
__version__ = '1.5.0'
3+
__version__ = '1.6.0'
44

55
import subprocess
66
import os
@@ -179,15 +179,18 @@ def _tagui_delta(base_directory = None):
179179
if os.path.isfile(base_directory + '/' + 'tagui_python_' + __version__): return True
180180

181181
# define list of key tagui files to be downloaded and synced locally
182-
delta_list = ['tagui', 'tagui.cmd', 'tagui_header.js', 'tagui_parse.php', 'tagui.sikuli/tagui.py']
182+
delta_list = ['tagui', 'tagui.cmd', 'end_processes', 'end_processes.cmd',
183+
'tagui_header.js', 'tagui_parse.php', 'tagui.sikuli/tagui.py']
184+
183185
for delta_file in delta_list:
184186
tagui_delta_url = 'https://raw.githubusercontent.com/tebelorg/Tump/master/TagUI-Python/' + delta_file
185187
tagui_delta_file = base_directory + '/' + 'src' + '/' + delta_file
186188
if not download(tagui_delta_url, tagui_delta_file): return False
187189

188-
# make sure execute permission is there for .tagui/src/tagui
190+
# make sure execute permission is there for .tagui/src/tagui and end_processes
189191
if platform.system() in ['Linux', 'Darwin']:
190192
os.system('chmod -R 755 ' + base_directory + '/' + 'src' + '/' + 'tagui > /dev/null 2>&1')
193+
os.system('chmod -R 755 ' + base_directory + '/' + 'src' + '/' + 'end_processes > /dev/null 2>&1')
191194

192195
# create marker file to skip syncing delta files next time for current release
193196
delta_done_file = _py23_open(base_directory + '/' + 'tagui_python_' + __version__, 'w')
@@ -399,6 +402,7 @@ def init(visual_automation = False, chrome_browser = True):
399402
tagui_directory = os.path.expanduser('~') + '/' + '.tagui'
400403

401404
tagui_executable = tagui_directory + '/' + 'src' + '/' + 'tagui'
405+
end_processes_executable = tagui_directory + '/' + 'src' + '/' + 'end_processes'
402406

403407
# if tagui executable is not found, initiate setup() to install tagui
404408
if not os.path.isfile(tagui_executable):
@@ -441,7 +445,11 @@ def init(visual_automation = False, chrome_browser = True):
441445

442446
# entry shell command to invoke tagui process
443447
tagui_cmd = tagui_executable + ' tagui_python ' + browser_option
444-
448+
449+
# run tagui end processes script to flush dead processes
450+
# for eg execution ended with ctrl+c or forget to close()
451+
os.system(end_processes_executable)
452+
445453
try:
446454
# launch tagui using subprocess
447455
_process = subprocess.Popen(

0 commit comments

Comments
 (0)