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 #3925Labels 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
- OS type and version
Linux, various flavours (problem observed on Arch with 4.12.8 and Ubuntu with 4.4.0)
- Python version and virtual environment information
python --version
3.5.2
- 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
- Stacktrace if available
completion_queue.poll() hangs on this line
- Steps to reproduce
Run code sample - hangs in topic.publish(...)
- 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)Activitynaveg commented on Sep 6, 2017 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). added type: bugError or flaw in code with unintended results or allowing sub-optimal usage patterns. on Sep 6, 2017tseaver commented on Sep 6, 2017 @naveg thanks for the report! I seem to recall that @lukesneeringer ran into some issues with multiprocessing in earlier versions of his rewrite. naveg commented on Sep 6, 2017 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)lukesneeringer commented on Sep 8, 2017 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? naveg commented on Sep 8, 2017 bradgrimm commented on Sep 11, 2017 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! lukesneeringer commented on Sep 12, 2017 nathanielmanistaatgoogle commented on Sep 13, 2017 (Should the title of this issue be changed from "completion_queue.call()" to "completion_queue.poll()"?) Reacted by Evan Goldenberg nathanielmanistaatgoogle commented on Sep 13, 2017 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? nathanielmanistaatgoogle commented on Sep 13, 2017 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, 2017lukesneeringer commented on Sep 14, 2017
MetadataMetadataapi: 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. DevelopmentNo branches or pull requestsIssue actions
|