Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3319360
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T22:48:55+00:00 2026-05-17T22:48:55+00:00

Is it possible to use python’s standard libs xmlrpclib with gevent? Currently i’m tried

  • 0

Is it possible to use python’s standard libs xmlrpclib with gevent? Currently i’m tried to use monkey.patch_all(), but without success.

from gevent import monkey
monkey.patch_all()

import gevent

import time

import xmlrpclib
from SimpleXMLRPCServer import SimpleXMLRPCServer

import urllib2

def fetch(url):
        g = gevent.spawn(urllib2.urlopen, url)
        return g.get().read()
def is_even(n):
    return n%2 == 0

def req(url):
        return fetch(url)

server = SimpleXMLRPCServer(("localhost", 8000))
print "Listening on port 8000..."
server.register_function(is_even, "is_even")
server.register_function(req, "req")
server.serve_forever()

urllib2.urlopen is blocking server. It looks to me, that monkey.patch_all did not patched socket, that’s why it blocks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T22:48:56+00:00Added an answer on May 17, 2026 at 10:48 pm

    The socket is patched fine, but there are other problems with your code.

    First, this

    def fetch(url):
        g = gevent.spawn(urllib2.urlopen, url)
        return g.get().read()
    

    is the same as

    def fetch(url):
        return urllib2.urlopen(url).read()
    

    You’re spawning a new greenlet here but then blocking the current one until that new one is done. It does not make things concurrent. It’s exactly the same as just running urlopen and waiting for it to finish.

    Second, in order to take advantage of gevent there got to be more than one lightweight thread (greenlet) running at the same time.

    SimpleXMLRPCServer, however, is defined as

    class SimpleXMLRPCServer(SocketServer.TCPServer,
                             SimpleXMLRPCDispatcher):
    

    which means it serves one connection at a time.

    If you make your own SimpleXMLRPCServer class, but use ThreadingTCPServer instead of TCPServer, you should be able to benefit from using gevent here.

    monkey.patch_all() patches threading to become greenlet-based, so such server will spawn a new greenlet for each new connection.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: What can you use Python generator functions for? I tried to read
I know that ufw is written in python. Is it possible to use ufw
Is it possible to use Python's doctest concept for classes, not just functions? If
is it possible to use python to create flash like browser games? (Actually I
I'm trying to use python to copy a tree of files/directories. is it possible
Is it possible to use P4Python (the perforce python api) with IronPython? I'd like
I know you can use python and other scripting languages in android. But I
Possible Duplicate: Multiprocessing launching too many instances of Python VM I'm trying to use
Is it possible to use XPath Query in Python while processing XML. I am
Is it possible to use the google app engine python imaging library, from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.