0

We switched to the python library to make it better integrated with our snippets, but it has some weird side-fx and only some operations behave other than the CLI version.

We were running the following command:

p4 sync //depot/test/...#head which would return `file(s) up-to-date, however doing the same thing with tye python API.

from P4 import P4, P4Exception

p4 = P4()
p4.port = "ssl:test:1666"
p4.user = "test-bot"
p4.client = "test-bot_projectX_wing0044"


p4.connect()
print("before run sync")
print p4.run_sync("{}/...#head".format("//depot/projectX"))
print("after run sync")
p4.disconnect()

if p4.errors:
    print(p4.errors)
if p4.warnings:
    print(p4.warnings)

Output:

python V:\tests\minimal.py
    before run sync
Traceback (most recent call last):
  File "V:\tests\minimal.py", line 11, in <module>
    print p4.run_sync("{}/...#head".format("//depot/projectX"))
  File "C:\Python27\lib\site-packages\P4.py", line 497, in <lambda>
    return lambda *args, **kargs: self.run(cmd, *args, **kargs)
  File "C:\Python27\lib\site-packages\P4.py", line 611, in run
    raise e
P4.P4Exception: [P4#run] Warnings during command execution( "p4 sync //depot/projectX/...#head" )

        [Warning]: '//depot/projectX/...#head - file(s) up-to-date.'

Doesn't return anything, further, it fails to execute any other p4 command that follows after this statement (between connect and disconnect). Further, any print statements after this failed operation are omitted. We are running this snippet in a try-catch block, however, run_sync doesn't seem to throw.

Edit: Based on samwise's comment I was catching p4.errors with P4Exception I've expanded that to p4.warnings and now I'm seeing Warnings during command execution( "p4 sync //depot/project/...#head")

However, that is exactly the same command that's being executed when I have p4v opened and I do a right mouse click on //depot/project and do get latest revision

user1767754
  • 23,311
  • 18
  • 141
  • 164
  • Does `run_sync` actually complete or does it get stuck there? Did you check for errors/warnings? Are you sure your connection settings are correct? – Samwise Jul 02 '20 at 14:10
  • Check out this answer for tips on making sure you're seeing all the errors/warnings coming back from a P4Python command: https://stackoverflow.com/a/60285961/3799759 – Samwise Jul 02 '20 at 14:14
  • Oh, I just caught the "`print` statements aren't executed" part. Yeah, the sync is just taking a long time, maybe because you're running it against a different workspace that's not up to date already? Or maybe you're using an output handler that's blocking? Or maybe you ran something earlier in the script that's holding a workspace lock? Try setting up a minimum reproducible example (I bet the problem will go away once you run this in isolation from the rest of your script)... – Samwise Jul 02 '20 at 16:33
  • I've realized, this happens only if I do `print p4.run_sync()` If I don't have the print there, the next statements (print and p4) seem to work. – user1767754 Jul 02 '20 at 17:08
  • Might be some quirk of Python 2's `print` statement? What if you add the `__future__` import and parens so `print` is being called as a function? – Samwise Jul 02 '20 at 17:21
  • i did impmort '__import__' and converted the print statements to `print()` but that didn't help :( – user1767754 Jul 02 '20 at 18:07
  • Maybe just assign the `run_sync` return value to a variable and print it later? /shrug – Samwise Jul 02 '20 at 19:33

1 Answers1

0

Here you are getting warning exception, You can solve it by exception level.

p4 = P4()
p4.port = "ssl:test:1666"
p4.user = "test-bot"
p4.client = "test-bot_projectX_wing0044"

p4.exception_level = 1 #it is 2 by default which means raise all.
p4.connect()

Refer Docs Perforce Exception

RahulAN
  • 97
  • 1
  • 1
  • 7