Skip to content

Instantly share code, notes, and snippets.

@altendky

altendky/x.py Secret

Last active March 20, 2019 16:02
Show Gist options
  • Save altendky/a1423f8519c4785283ee723106ef5e8b to your computer and use it in GitHub Desktop.
Save altendky/a1423f8519c4785283ee723106ef5e8b to your computer and use it in GitHub Desktop.
"""
Run such as:
venv/bin/python rundevice.py --device-path "interface/devices/DG 247 Factory.epz"
"""
import click
import epyqlib.hildevice
import epyqlib.utils.twisted
import twisted.internet.defer
import twisted.internet.reactor
import twisted.internet.task
def react_async_helper(reactor, f, args, kwargs):
return twisted.internet.defer.ensureDeferred(
f(reactor, *args, **kwargs),
)
def react_async(f, *args, **kwargs):
twisted.internet.task.react(react_async_helper, (f, args, kwargs))
@click.command()
@click.option(
'--device-path',
type=click.Path(exists=True, dir_okay=False, resolve_path=True),
required=True,
)
def command(device_path):
react_async(async_main, device_path=device_path)
async def async_main(reactor, device_path):
device = epyqlib.hildevice.Device(definition_path=device_path)
print('about to sleep')
await epyqlib.utils.twisted.sleep(1)
print('slept 1')
await epyqlib.utils.twisted.sleep(1)
print('slept 1')
command()
@altendky
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment