GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — PubSub publish hangs in completion_queue.poll() when used inside ProcessPoolExecutor · Issue #3925 · googleapis/google-cloud-python

PubSub publish hangs in completion_queue.poll() when used inside ProcessPoolExecutor #3925

New issue
Copy link
New issue
Copy link
Closed
Closed
PubSub publish hangs in completion_queue.poll() when used inside ProcessPoolExecutor#3925
Copy link
Assignees
lukesneeringer
Labels
api: pubsubIssues related to the Pub/Sub API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Description

@naveg
naveg
opened on Sep 6, 2017
Issue body actions
  1. OS type and version

Linux, various flavours (problem observed on Arch with 4.12.8 and Ubuntu with 4.4.0)

  1. Python version and virtual environment information python --version

3.5.2

  1. google-cloud-python version pip show google-cloud, pip show google-<service> or pip freeze
appdirs==1.4.3
asn1crypto==0.22.0
astroid==1.4.9
beautifulsoup4==4.5.3
bots==3.3.1.dev0
cachetools==2.0.0
certifi==2017.7.27.1
cffi==1.10.0
chardet==3.0.4
cheroot==5.8.3
CherryPy==10.2.2
click==6.7
cryptography==2.0.3
decorator==4.1.2
dill==0.2.7.1
Django==1.8
dropbox==7.2.1
enum34==1.1.6
et-xmlfile==1.0.1
fake-useragent==0.1.4
ftputil==3.3.1
future==0.16.0
gapic-google-cloud-datastore-v1==0.15.3
gapic-google-cloud-error-reporting-v1beta1==0.15.3
gapic-google-cloud-logging-v2==0.91.3
gapic-google-cloud-pubsub-v1==0.15.4
gapic-google-cloud-spanner-admin-database-v1==0.15.3
gapic-google-cloud-spanner-admin-instance-v1==0.15.3
gapic-google-cloud-spanner-v1==0.15.3
geocoder==1.20.1
google-auth==1.0.2
google-auth-httplib2==0.0.2
google-cloud==0.27.0
google-cloud-bigquery==0.26.0
google-cloud-bigtable==0.26.0
google-cloud-core==0.26.0
google-cloud-datastore==1.2.0
google-cloud-dns==0.26.0
google-cloud-error-reporting==0.26.0
google-cloud-happybase==0.22.0
google-cloud-language==0.27.0
google-cloud-logging==1.2.0
google-cloud-monitoring==0.26.0
google-cloud-pubsub==0.27.0
google-cloud-resource-manager==0.26.0
google-cloud-runtimeconfig==0.26.0
google-cloud-spanner==0.26.0
google-cloud-speech==0.28.0
google-cloud-storage==1.3.2
google-cloud-translate==1.1.0
google-cloud-videointelligence==0.25.0
google-cloud-vision==0.26.0
google-gax==0.15.14
google-resumable-media==0.2.3
googleapis-common-protos==1.5.2
grpc-google-cloud-datastore-v1==0.14.0
grpc-google-cloud-logging-v2==0.90.0
grpc-google-cloud-pubsub-v1==0.14.0
grpc-google-iam-v1==0.11.1
grpcio==1.6.0
httplib2==0.10.3
hvac==0.2.17
idna==2.6
ipdb==0.10.2
ipython==5.3.0
ipython-genutils==0.2.0
isort==4.2.15
jdcal==1.3
lazy-object-proxy==1.3.1
lxml==3.7.3
magento==2.1
mccabe==0.6.1
monotonic==1.3
oauth2client==3.0.0
openpyxl==2.4.4
packaging==16.8
paramiko==2.1.1
pexpect==4.2.1
pickleshare==0.7.4
ply==3.8
portend==2.1.2
prompt-toolkit==1.0.14
proto-google-cloud-datastore-v1==0.90.4
proto-google-cloud-error-reporting-v1beta1==0.15.3
proto-google-cloud-logging-v2==0.91.3
proto-google-cloud-pubsub-v1==0.15.4
proto-google-cloud-spanner-admin-database-v1==0.15.3
proto-google-cloud-spanner-admin-instance-v1==0.15.3
proto-google-cloud-spanner-v1==0.15.3
protobuf==3.4.0
psycopg2==2.6.2
ptyprocess==0.5.1
py==1.4.34
pyasn1==0.3.3
pyasn1-modules==0.1.1
pycparser==2.18
Pygments==2.2.0
pyinotify==0.9.6
pylint==1.6.5
pyparsing==2.2.0
pytest==3.0.6
python-amazon-mws==0.6
python-dateutil==2.6.0
pytz==2017.2
PyYAML==3.12
ratelim==0.1.6
requests==2.18.4
retrying==1.3.3
rsa==3.4.2
selenium==3.0.2
simplegeneric==0.8.1
six==1.10.0
SQLAlchemy==1.1.5
suds-jurko==0.6
tempora==1.9
tenacity==4.4.0
traitlets==4.3.2
typing==3.6.2
ujson==1.35
urllib3==1.22
wcwidth==0.1.7
winpdb==1.3.6
wrapt==1.10.11
xlrd==1.0.0
  1. Stacktrace if available

completion_queue.poll() hangs on this line

  1. Steps to reproduce

Run code sample - hangs in topic.publish(...)

  1. Code example
from concurrent.futures import ProcessPoolExecutor
from time import sleep
from google.cloud import pubsub

def start_publishing(task):
    client = pubsub.Client()
    topic = client.topic('my-topic')
    for i in range(5):
        print('task {}, publishing {}'.format(task, i))
        topic.publish('this is a test ' + str(i))
        print('task {}, published {}'.format(task, i))
        sleep(1)

def done(future):
    r = future.result()
    print(r)

if __name__ == '__main__':
    executor = ProcessPoolExecutor(max_workers=4)
    for t in range(4):
        future = executor.submit(start_publishing, t)
        future.add_done_callback(done)

Activity

  1. naveg commented on Sep 6, 2017

    @naveg
    naveg
    on Sep 6, 2017
    Author
    More actions

    Note that the code sample works when a ThreadPoolExecutor is used instead of a ProcessPoolExecutor. Our use case is CPU heavy, and we need to use a ProcessPoolExecutor.

    This broke in production recently, with no change to the environment that we are aware of (python or dependency versions, etc).

  2. tseaver
    added
    api: pubsubIssues related to the Pub/Sub API.
    type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.
    on Sep 6, 2017
  3. tseaver commented on Sep 6, 2017

    @tseaver
    tseaver
    on Sep 6, 2017
    Contributor
    More actions

    @naveg thanks for the report! I seem to recall that @lukesneeringer ran into some issues with multiprocessing in earlier versions of his rewrite.

  4. naveg commented on Sep 6, 2017

    @naveg
    naveg
    on Sep 6, 2017
    Author
    More actions

    I tried with pubsub 0.28.3 - same thing. Hangs on client.publish(...).result() (result() is added so that we wait for the publsh to finish, since it is asynchronous in the new version)

    def start_publishing(task):
        client = pubsub.PublisherClient()
        topic = 'my-topic'
        for i in range(10):
            print('task {}, publishing {}'.format(task, i))
            print(client.publish(topic, b'this is a test').result())
            print('task {}, published {}'.format(task, i))
            sleep(1)
  5. lukesneeringer
    self-assigned this
    on Sep 8, 2017
  6. lukesneeringer
    added
    priority: p2Moderately-important priority. Fix may not be included in next release.
    on Sep 8, 2017
  7. lukesneeringer commented on Sep 8, 2017

    @lukesneeringer
    lukesneeringer
    on Sep 8, 2017
    Contributor
    More actions

    I will look into this. When it broke in production, was there a library upgrade, or did it literally just break in-place?

    My new publishing code uses threading but has a mechanism to sub out for multiprocessing, but I am unsure how exactly it is interacting with your code.

    Also: You mention your process is CPU heavy, but presumably the publish itself is not? Can you explain to me a bit more what you are doing?

  8. naveg commented on Sep 8, 2017

    @naveg
    naveg
    on Sep 8, 2017
    Author
    More actions

    The problem appears to be grpcio 1.6.0.

    pip install grpcio==1.6.0
    python -m pubsub-test
    
    Hangs!
    
    pip install grpcio==1.4.0
    python -m pubsub-test
    
    Works!
    

    It broke after a release of our software that did not contain any explicit library updates in our requirements file. However, it looks like gcloud-pubsub doesn't depend on a specific grpcio version https://github.com/GoogleCloudPlatform/google-cloud-python/blob/4e17158c0f14e0e91cbeb74c3e8483c5a231e9ac/pubsub/setup.py#L58

    Adding an explicit dependency on grpcio==1.4.0 seems to work.

    Let me know if I should open an issue on grpc or if you can take it from here.

  9. bradgrimm commented on Sep 11, 2017

    @bradgrimm
    bradgrimm
    on Sep 11, 2017
    More actions

    We ran into the same problem when trying to run long_running_recognize. In our case it showed up only when the code was run in a celery task. The workaround by Naveg seems to work for us as well. Thanks!

  10. lukesneeringer commented on Sep 12, 2017

    @lukesneeringer
    lukesneeringer
    on Sep 12, 2017
    Contributor
    More actions

    Summoning @nathanielmanistaatgoogle.

  11. nathanielmanistaatgoogle commented on Sep 13, 2017

    @nathanielmanistaatgoogle
    nathanielmanistaatgoogle
    on Sep 13, 2017
    More actions

    (Should the title of this issue be changed from "completion_queue.call()" to "completion_queue.poll()"?)

    Reacted by Evan Goldenberg
  12. nathanielmanistaatgoogle commented on Sep 13, 2017

    @nathanielmanistaatgoogle
    nathanielmanistaatgoogle
    on Sep 13, 2017
    More actions

    Not much changed in the Python layer of gRPC Python between 1.4 and 1.6, but probably a lot changed underneath us in gRPC Core. I suspect that the real problem is that forking/multiprocessing/working across processes has not to date ever been supported by gRPC Core (unfortunately this is the best citation I can find at the moment), so while something may happened to have worked with 1.4 it silently broke with 1.6.

    One workaround might be "delay invoking anything from gRPC until after forking/running in the child process", but I'm not sure.

    Can the reproduction described above have the google.cloud bits boiled away from it into just a minimal using-grpc-directly demonstration?

  13. nathanielmanistaatgoogle commented on Sep 13, 2017

    @nathanielmanistaatgoogle
    nathanielmanistaatgoogle
    on Sep 13, 2017
    More actions

    (Also is this issue 12455 or is this something else?)

  14. naveg
    changed the title [-]PubSub publish hangs in completion_queue.call() when used inside ProcessPoolExecutor[/-] [+]PubSub publish hangs in completion_queue.poll() when used inside ProcessPoolExecutor[/+] on Sep 13, 2017
  15. lukesneeringer commented on Sep 14, 2017

    @lukesneeringer
    lukesneeringer
    on Sep 14, 2017
    Contributor
    More actions

    @nathanielmanistaatgoogle Pretty sure this is yet another iteration of grpc/grpc#12455.

  16. lukesneeringer
    closed this as completedin gax-python#199on Sep 18, 2017
  17. parthea
    added a commit that references this issue on Sep 22, 2023

    chore: move samples from python-docs-sample (#33)

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

Metadata

Metadata

Assignees

  • @lukesneeringer
    lukesneeringer

Labels

api: pubsubIssues related to the Pub/Sub API.priority: p2Moderately-important priority. Fix may not be included in next release.type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402775 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.