python - Is my fabric code actually multithreading? -


i attempting multi-threaded solution using gevent set of tasks, of use fabric api. when trying monkeypatch, fabric fails read env , prompts password. when not patching works, execution not appear asynchronous. created following toy example question:

from gevent import monkey, spawn, sleep, joinall monkey.patch_socket()  # if removed, "appears to" runs serial fabric.api import run, env, settings  import os  env.use_ssh_config = true env.host_string = "user@remotehost" env.user = "user" env.key_filename = os.path.expanduser('~/.ssh/id_rsa_4096') env.password = "" env.port = 22  def toytask(char):     command = "ls %s*" %char     print command     settings(warn_only=true):         run(command)     sleep()  charlist = list(map(chr,range(97,123))) # creates ['a','b',...........'z'] threads = [spawn(toytask, char) char in charlist] joinall(threads) 

in current form, returns:

me@localhost:~$ python gevent_fab.py
ls a*
[user@remotehost] run: ls a*
ls b*
[user@remotehost] run: ls b*
ls c*

..

..

[user@remotehost] run: ls z*
ls z*

no handlers found logger "paramiko.transport"
[user@remotehost] login password 'user':

if monkey.patch_socket removed, fabric no longer prompts password , returns expected output follows:

ls a*
[user@remotehost] run: ls a*
[user@remotehost] out: kegg.csh kegg.pl
[user@remotehost] out:

ls b*
[user@remotehost] run: ls b*
[user@remotehost] out: bin:
[user@remotehost] out: afiedt.buf hash_mod.py-orig renamepat.pl

ls c*

..

..

ls z*
[user@remotehost] run: ls z*
[user@remotehost] out: ls: cannot access z*: no such file or directory
[user@remotehost] out

my questions are:

  1. is code parallelizing toytask @ although output appears serial?
  2. why fabric prompt password when calling monkey.patch_socket()?


Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -