Re: [pysnmp-users] CLI interaction?
Brought to you by:
elie
From: Craig S. <cs...@en...> - 2015-11-14 00:42:15
|
On Wed, Nov 11, 2015 at 06:56:36PM -0600, Michael R Anderson wrote: > I am using cly to drive my CLI. It works great. I recently added > pysmp. Now when it gets to runDispatcher() (in it's own thread), it > looks like my CLI input line gets hijacked so that no more command > line input can be done. I actually have written some test code showing a simple stdin reader working with pysnmp. It happily loops around servicing the snmp sockets and the stdin socket. Even uses the nice new hlapi (nice work Ilya). I thought, ok good, you get the data from stdin and feed it into cly and the world is good. but... cly uses raw_input[1] and that blocks :( So you have options: 1) re-write a cly InputDriver that doesn't use raw_input() but something a little less block-happy 2) Use threads, one for the input, one for SNMP and somehow get them to talk to each other (but you might have a raw_input blocks on my IPC socket problem anyhow) 3) Use a simple stdin input and somehow wedge the input characters into cly's parser. 4) Depending on the design of the app, either have cly running or SNMP running but not both. The last option would mean using your own Interact class and running every until some flag changed, the interact would need to make that check function below return true when it wants snmp to run. while True: while doInput: myInteract.once() if checkWeShouldDoSomeSnmpNow(): doInput = False else: # Now we sit here doing SNMP transportDispatcher.runDispatcher() doInput = True or something like that. - Craig [1] https://github.com/alecthomas/cly/blob/master/cly/interactive.py#L131 -- Craig Small (@smallsees) http://enc.com.au/ csmall at : enc.com.au Debian GNU/Linux http://www.debian.org/ csmall at : debian.org GPG fingerprint: 5D2F B320 B825 D939 04D2 0519 3938 F96B DF50 FEA5 |